/*      */ package com.zimbra.cs.account.soap;
/*      */ 
/*      */ import com.zimbra.common.account.Key.AccountBy;
/*      */ import com.zimbra.common.account.Key.AlwaysOnClusterBy;
/*      */ import com.zimbra.common.account.Key.CacheEntryBy;
/*      */ import com.zimbra.common.account.Key.CalendarResourceBy;
/*      */ import com.zimbra.common.account.Key.CosBy;
/*      */ import com.zimbra.common.account.Key.DistributionListBy;
/*      */ import com.zimbra.common.account.Key.DomainBy;
/*      */ import com.zimbra.common.account.Key.ServerBy;
/*      */ import com.zimbra.common.account.Key.UCServiceBy;
/*      */ import com.zimbra.common.account.Key.XMPPComponentBy;
/*      */ import com.zimbra.common.auth.ZAuthToken;
/*      */ import com.zimbra.common.localconfig.KnownKey;
/*      */ import com.zimbra.common.localconfig.LC;
/*      */ import com.zimbra.common.service.ServiceException;
/*      */ import com.zimbra.common.soap.AccountConstants;
/*      */ import com.zimbra.common.soap.AdminConstants;
/*      */ import com.zimbra.common.soap.Element;
/*      */ import com.zimbra.common.soap.Element.XMLElement;
/*      */ import com.zimbra.common.soap.SoapFaultException;
/*      */ import com.zimbra.common.soap.SoapHttpTransport;
/*      */ import com.zimbra.common.soap.SoapHttpTransport.HttpDebugListener;
/*      */ import com.zimbra.common.soap.SoapTransport.DebugListener;
/*      */ import com.zimbra.common.util.AccountLogger;
/*      */ import com.zimbra.common.zclient.ZClientException;
/*      */ import com.zimbra.cs.account.AccessManager.ViaGrant;
/*      */ import com.zimbra.cs.account.Account;
/*      */ import com.zimbra.cs.account.AlwaysOnCluster;
/*      */ import com.zimbra.cs.account.CalendarResource;
/*      */ import com.zimbra.cs.account.Cos;
/*      */ import com.zimbra.cs.account.DataSource;
/*      */ import com.zimbra.cs.account.DistributionList;
/*      */ import com.zimbra.cs.account.Domain;
/*      */ import com.zimbra.cs.account.Entry;
/*      */ import com.zimbra.cs.account.Group;
/*      */ import com.zimbra.cs.account.NamedEntry.Visitor;
/*      */ import com.zimbra.cs.account.Provisioning.CacheEntry;
/*      */ import com.zimbra.cs.account.Provisioning.CountAccountResult;
/*      */ import com.zimbra.cs.account.Provisioning.PublishedShareInfoVisitor;
/*      */ import com.zimbra.cs.account.Provisioning.RightsDoc;
/*      */ import com.zimbra.cs.account.Provisioning.SearchGalResult;
/*      */ import com.zimbra.cs.account.Provisioning.SetPasswordResult;
/*      */ import com.zimbra.cs.account.SearchDirectoryOptions;
/*      */ import com.zimbra.cs.account.Server;
/*      */ import com.zimbra.cs.account.Signature;
/*      */ import com.zimbra.cs.account.UCService;
/*      */ import com.zimbra.cs.account.XMPPComponent;
/*      */ import com.zimbra.cs.account.Zimlet;
/*      */ import com.zimbra.cs.account.accesscontrol.Right;
/*      */ import com.zimbra.cs.account.accesscontrol.RightCommand.EffectiveRights;
/*      */ import com.zimbra.cs.account.accesscontrol.RightModifier;
/*      */ import com.zimbra.cs.account.auth.AuthContext.Protocol;
/*      */ import com.zimbra.soap.JaxbUtil;
/*      */ import com.zimbra.soap.account.message.CreateIdentityResponse;
/*      */ import com.zimbra.soap.account.message.GetIdentitiesResponse;
/*      */ import com.zimbra.soap.admin.message.AddAccountLoggerResponse;
/*      */ import com.zimbra.soap.admin.message.CheckHealthResponse;
/*      */ import com.zimbra.soap.admin.message.CompactIndexResponse;
/*      */ import com.zimbra.soap.admin.message.CopyCosResponse;
/*      */ import com.zimbra.soap.admin.message.CountAccountResponse;
/*      */ import com.zimbra.soap.admin.message.CountObjectsResponse;
/*      */ import com.zimbra.soap.admin.message.CreateAccountResponse;
/*      */ import com.zimbra.soap.admin.message.CreateAlwaysOnClusterResponse;
/*      */ import com.zimbra.soap.admin.message.CreateCalendarResourceResponse;
/*      */ import com.zimbra.soap.admin.message.CreateCosResponse;
/*      */ import com.zimbra.soap.admin.message.CreateDistributionListRequest;
/*      */ import com.zimbra.soap.admin.message.CreateDistributionListResponse;
/*      */ import com.zimbra.soap.admin.message.CreateDomainResponse;
/*      */ import com.zimbra.soap.admin.message.CreateServerResponse;
/*      */ import com.zimbra.soap.admin.message.CreateUCServiceResponse;
/*      */ import com.zimbra.soap.admin.message.GetAccountLoggersResponse;
/*      */ import com.zimbra.soap.admin.message.GetAccountMembershipResponse;
/*      */ import com.zimbra.soap.admin.message.GetAccountResponse;
/*      */ import com.zimbra.soap.admin.message.GetAllAccountLoggersResponse;
/*      */ import com.zimbra.soap.admin.message.GetAllAccountsResponse;
/*      */ import com.zimbra.soap.admin.message.GetAllActiveServersResponse;
/*      */ import com.zimbra.soap.admin.message.GetAllAdminAccountsResponse;
/*      */ import com.zimbra.soap.admin.message.GetAllAlwaysOnClustersResponse;
/*      */ import com.zimbra.soap.admin.message.GetAllCalendarResourcesResponse;
/*      */ import com.zimbra.soap.admin.message.GetAllCosResponse;
/*      */ import com.zimbra.soap.admin.message.GetAllDistributionListsResponse;
/*      */ import com.zimbra.soap.admin.message.GetAllDomainsResponse;
/*      */ import com.zimbra.soap.admin.message.GetAllRightsResponse;
/*      */ import com.zimbra.soap.admin.message.GetAllServersResponse;
/*      */ import com.zimbra.soap.admin.message.GetAllUCServicesResponse;
/*      */ import com.zimbra.soap.admin.message.GetAlwaysOnClusterResponse;
/*      */ import com.zimbra.soap.admin.message.GetCalendarResourceResponse;
/*      */ import com.zimbra.soap.admin.message.GetConfigRequest;
/*      */ import com.zimbra.soap.admin.message.GetCosResponse;
/*      */ import com.zimbra.soap.admin.message.GetDistributionListMembershipResponse;
/*      */ import com.zimbra.soap.admin.message.GetDistributionListResponse;
/*      */ import com.zimbra.soap.admin.message.GetDomainInfoResponse;
/*      */ import com.zimbra.soap.admin.message.GetDomainResponse;
/*      */ import com.zimbra.soap.admin.message.GetEffectiveRightsResponse;
/*      */ import com.zimbra.soap.admin.message.GetIndexStatsResponse;
/*      */ import com.zimbra.soap.admin.message.GetMailboxResponse;
/*      */ import com.zimbra.soap.admin.message.GetQuotaUsageResponse;
/*      */ import com.zimbra.soap.admin.message.GetRightResponse;
/*      */ import com.zimbra.soap.admin.message.GetRightsDocRequest;
/*      */ import com.zimbra.soap.admin.message.GetRightsDocResponse;
/*      */ import com.zimbra.soap.admin.message.GetServerResponse;
/*      */ import com.zimbra.soap.admin.message.GetShareInfoResponse;
/*      */ import com.zimbra.soap.admin.message.GetUCServiceResponse;
/*      */ import com.zimbra.soap.admin.message.PurgeMessagesResponse;
/*      */ import com.zimbra.soap.admin.message.ReIndexResponse;
/*      */ import com.zimbra.soap.admin.message.RecalculateMailboxCountsResponse;
/*      */ import com.zimbra.soap.admin.message.RemoveAccountLoggerResponse;
/*      */ import com.zimbra.soap.admin.message.RemoveDistributionListAliasRequest;
/*      */ import com.zimbra.soap.admin.message.SearchDirectoryRequest;
/*      */ import com.zimbra.soap.admin.message.SearchDirectoryResponse;
/*      */ import com.zimbra.soap.admin.message.SetPasswordResponse;
/*      */ import com.zimbra.soap.admin.message.UpdatePresenceSessionIdResponse;
/*      */ import com.zimbra.soap.admin.message.VerifyIndexResponse;
/*      */ import com.zimbra.soap.admin.type.AccountInfo;
/*      */ import com.zimbra.soap.admin.type.AccountLoggerInfo;
/*      */ import com.zimbra.soap.admin.type.AccountQuotaInfo;
/*      */ import com.zimbra.soap.admin.type.Attr;
/*      */ import com.zimbra.soap.admin.type.CacheEntryType;
/*      */ import com.zimbra.soap.admin.type.CacheSelector;
/*      */ import com.zimbra.soap.admin.type.CalendarResourceInfo;
/*      */ import com.zimbra.soap.admin.type.CosCountInfo;
/*      */ import com.zimbra.soap.admin.type.CosSelector.CosBy;
/*      */ import com.zimbra.soap.admin.type.DLInfo;
/*      */ import com.zimbra.soap.admin.type.DataSourceType;
/*      */ import com.zimbra.soap.admin.type.DistributionListInfo;
/*      */ import com.zimbra.soap.admin.type.DomainInfo;
/*      */ import com.zimbra.soap.admin.type.DomainSelector;
/*      */ import com.zimbra.soap.admin.type.GranteeSelector;
/*      */ import com.zimbra.soap.admin.type.GranteeSelector.GranteeBy;
/*      */ import com.zimbra.soap.admin.type.LoggerInfo;
/*      */ import com.zimbra.soap.admin.type.MailboxByAccountIdSelector;
/*      */ import com.zimbra.soap.admin.type.MailboxWithMailboxId;
/*      */ import com.zimbra.soap.admin.type.PackageRightsInfo;
/*      */ import com.zimbra.soap.admin.type.ReindexMailboxInfo;
/*      */ import com.zimbra.soap.admin.type.ReindexProgressInfo;
/*      */ import com.zimbra.soap.admin.type.RightInfo;
/*      */ import com.zimbra.soap.admin.type.ServerInfo;
/*      */ import com.zimbra.soap.admin.type.ServerSelector;
/*      */ import com.zimbra.soap.admin.type.UCServiceSelector;
/*      */ import com.zimbra.soap.type.AccountBy;
/*      */ import com.zimbra.soap.type.AccountSelector;
/*      */ import com.zimbra.soap.type.GalSearchType;
/*      */ import com.zimbra.soap.type.TargetBy;
/*      */ import java.io.IOException;
/*      */ import java.util.ArrayList;
/*      */ import java.util.Arrays;
/*      */ import java.util.HashMap;
/*      */ import java.util.List;
/*      */ import java.util.Map;
/*      */ import java.util.Map.Entry;
/*      */ import java.util.Set;
/*      */ 
/*      */ public class SoapProvisioning extends com.zimbra.cs.account.Provisioning
/*      */ {
/*      */   public static class Options
/*      */   {
/*      */     private String mAccount;
/*  159 */     private Key.AccountBy mAccountBy = Key.AccountBy.name;
/*      */     private String mPassword;
/*      */     private ZAuthToken mAuthToken;
/*      */     private String mUri;
/*  163 */     private int mTimeout = -1;
/*  164 */     private int mRetryCount = -1;
/*      */     private SoapTransport.DebugListener mDebugListener;
/*      */     private boolean mLocalConfigAuth;
/*      */     private boolean mNeedSession;
/*      */     
/*      */     public Options() {}
/*      */     
/*      */     public Options(String account, Key.AccountBy accountBy, String password, String uri)
/*      */     {
/*  173 */       this.mAccount = account;
/*  174 */       this.mAccountBy = accountBy;
/*  175 */       this.mPassword = password;
/*  176 */       this.mUri = uri;
/*      */     }
/*      */     
/*      */     public Options(String authToken, String uri)
/*      */     {
/*  181 */       this.mAuthToken = new ZAuthToken(null, authToken, null);
/*  182 */       this.mUri = uri;
/*      */     }
/*      */     
/*      */     public Options(ZAuthToken authToken, String uri) {
/*  186 */       this.mAuthToken = authToken;
/*  187 */       this.mUri = uri;
/*      */     }
/*      */     
/*  190 */     public String getAccount() { return this.mAccount; }
/*  191 */     public void setAccount(String account) { this.mAccount = account; }
/*      */     
/*  193 */     public Key.AccountBy getAccountBy() { return this.mAccountBy; }
/*  194 */     public void setAccountBy(Key.AccountBy accountBy) { this.mAccountBy = accountBy; }
/*      */     
/*  196 */     public String getPassword() { return this.mPassword; }
/*  197 */     public void setPassword(String password) { this.mPassword = password; }
/*      */     
/*  199 */     public ZAuthToken getAuthToken() { return this.mAuthToken; }
/*  200 */     public void setAuthToken(ZAuthToken authToken) { this.mAuthToken = authToken; }
/*      */     
/*      */ 
/*  203 */     public void setAuthToken(String authToken) { this.mAuthToken = new ZAuthToken(null, authToken, null); }
/*      */     
/*  205 */     public String getUri() { return this.mUri; }
/*  206 */     public void setUri(String uri) { this.mUri = uri; }
/*      */     
/*  208 */     public int getTimeout() { return this.mTimeout; }
/*  209 */     public void setTimeout(int timeout) { this.mTimeout = timeout; }
/*      */     
/*  211 */     public int getRetryCount() { return this.mRetryCount; }
/*  212 */     public void setRetryCount(int retryCount) { this.mRetryCount = retryCount; }
/*      */     
/*  214 */     public SoapTransport.DebugListener getDebugListener() { return this.mDebugListener; }
/*  215 */     public void setDebugListener(SoapTransport.DebugListener liistener) { this.mDebugListener = liistener; }
/*      */     
/*  217 */     public boolean getLocalConfigAuth() { return this.mLocalConfigAuth; }
/*  218 */     public void setLocalConfigAuth(boolean auth) { this.mLocalConfigAuth = auth; }
/*      */     
/*  220 */     public boolean getNeedSession() { return this.mNeedSession; }
/*  221 */     public void setNeedSession(boolean needSession) { this.mNeedSession = needSession; }
/*      */   }
/*      */   
/*      */ 
/*  225 */   private int mTimeout = -1;
/*      */   
/*      */   private int mRetryCount;
/*      */   
/*      */   private SoapHttpTransport mTransport;
/*      */   private ZAuthToken mAuthToken;
/*      */   private String mCsrfToken;
/*      */   private long mAuthTokenLifetime;
/*      */   private long mAuthTokenExpiration;
/*      */   
/*      */   public SoapProvisioning()
/*      */   {
/*  237 */     this.mNeedSession = false;
/*      */   }
/*      */   
/*      */   public SoapProvisioning(boolean needSession) {
/*  241 */     this.mNeedSession = needSession;
/*      */   }
/*      */   
/*      */   public SoapProvisioning(Options options) throws ServiceException {
/*  245 */     this.mTimeout = options.getTimeout();
/*  246 */     this.mRetryCount = options.getRetryCount();
/*  247 */     this.mDebugListener = options.getDebugListener();
/*  248 */     this.mAuthToken = options.getAuthToken();
/*  249 */     this.mNeedSession = options.getNeedSession();
/*  250 */     if (options.getUri() == null) options.setUri(getLocalConfigURI());
/*  251 */     soapSetURI(options.getUri());
/*      */     
/*  253 */     if (options.getLocalConfigAuth()) {
/*  254 */       soapZimbraAdminAuthenticate();
/*  255 */     } else if (this.mAuthToken != null) {
/*  256 */       soapAdminAuthenticate(this.mAuthToken);
/*  257 */     } else if ((options.getAccount() != null) && (options.getPassword() != null))
/*      */     {
/*      */ 
/*  260 */       Element.XMLElement req = new Element.XMLElement(AdminConstants.AUTH_REQUEST);
/*  261 */       switch (options.getAccountBy()) {
/*      */       case name: 
/*  263 */         req.addElement("name").setText(options.getAccount());
/*  264 */         break;
/*      */       default: 
/*  266 */         Element account = req.addElement("account");
/*  267 */         account.addAttribute("by", options.getAccountBy().name());
/*  268 */         account.setText(options.getAccount());
/*      */       }
/*      */       
/*  271 */       req.addElement("password").setText(options.getPassword());
/*  272 */       Element response = invoke(req);
/*  273 */       this.mAuthToken = new ZAuthToken(response.getElement("authToken"), true);
/*  274 */       this.mAuthTokenLifetime = response.getAttributeLong("lifetime");
/*  275 */       this.mAuthTokenExpiration = (System.currentTimeMillis() + this.mAuthTokenLifetime);
/*  276 */       this.mTransport.setAuthToken(this.mAuthToken);
/*      */     } else {
/*  278 */       throw ZClientException.CLIENT_ERROR("no valid authentication method selected", null);
/*      */     }
/*      */   }
/*      */   
/*      */   public String toString()
/*      */   {
/*  284 */     return String.format("[%s %s]", new Object[] { getClass().getName(), this.mTransport == null ? "" : this.mTransport.getURI() });
/*      */   }
/*      */   
/*      */   public boolean isExpired()
/*      */   {
/*  289 */     return this.mAuthTokenExpiration <= System.currentTimeMillis();
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   public void soapSetURI(String uri)
/*      */   {
/*  297 */     if (this.mTransport != null) this.mTransport.shutdown();
/*  298 */     this.mTransport = new SoapHttpTransport(uri);
/*  299 */     if (this.mTimeout >= 0)
/*  300 */       this.mTransport.setTimeout(this.mTimeout);
/*  301 */     if (this.mRetryCount > 0)
/*  302 */       this.mTransport.setRetryCount(this.mRetryCount);
/*  303 */     if (this.mAuthToken != null)
/*  304 */       this.mTransport.setAuthToken(this.mAuthToken);
/*  305 */     if (this.mDebugListener != null)
/*  306 */       this.mTransport.setDebugListener(this.mDebugListener);
/*      */   }
/*      */   
/*      */   public static String getLocalConfigURI() {
/*  310 */     String server = LC.zimbra_zmprov_default_soap_server.value();
/*  311 */     int port = LC.zimbra_admin_service_port.intValue();
/*  312 */     return LC.zimbra_admin_service_scheme.value() + server + ":" + port + "/service/admin/soap/";
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public static SoapProvisioning getAdminInstance()
/*      */     throws ServiceException
/*      */   {
/*  324 */     return getAdminInstance(false);
/*      */   }
/*      */   
/*      */   public static SoapProvisioning getAdminInstance(boolean needSession) throws ServiceException
/*      */   {
/*  329 */     Options opts = new Options();
/*  330 */     opts.setLocalConfigAuth(true);
/*  331 */     opts.setNeedSession(needSession);
/*  332 */     return new SoapProvisioning(opts);
/*      */   }
/*      */   
/*      */   public String soapGetURI() {
/*  336 */     return this.mTransport.getURI();
/*      */   }
/*      */   
/*      */   public void soapSetTransportTimeout(int timeout) {
/*  340 */     this.mTimeout = timeout;
/*  341 */     if ((this.mTransport != null) && (timeout >= 0))
/*  342 */       this.mTransport.setTimeout(timeout);
/*      */   }
/*      */   
/*      */   public void soapSetTransportRetryCount(int retryCount) {
/*  346 */     this.mRetryCount = retryCount;
/*  347 */     if ((this.mTransport != null) && (retryCount >= 0))
/*  348 */       this.mTransport.setRetryCount(retryCount);
/*      */   }
/*      */   
/*      */   public void soapSetTransportDebugListener(SoapTransport.DebugListener listener) {
/*  352 */     this.mDebugListener = listener;
/*  353 */     if (this.mTransport != null)
/*  354 */       this.mTransport.setDebugListener(this.mDebugListener);
/*      */   }
/*      */   
/*      */   public SoapTransport.DebugListener soapGetTransportDebugListener() {
/*  358 */     return this.mDebugListener;
/*      */   }
/*      */   
/*      */   public void soapSetHttpTransportDebugListener(SoapHttpTransport.HttpDebugListener listener) {
/*  362 */     this.mHttpDebugListener = listener;
/*  363 */     if (this.mTransport != null)
/*  364 */       this.mTransport.setHttpDebugListener(listener);
/*      */   }
/*      */   
/*      */   public SoapHttpTransport.HttpDebugListener soapGetHttpTransportDebugListener() {
/*  368 */     return this.mHttpDebugListener;
/*      */   }
/*      */   
/*      */   public ZAuthToken getAuthToken() {
/*  372 */     return this.mAuthToken;
/*      */   }
/*      */   
/*      */   public void setAuthToken(ZAuthToken authToken) {
/*  376 */     this.mAuthToken = authToken;
/*  377 */     if (this.mTransport != null)
/*  378 */       this.mTransport.setAuthToken(authToken);
/*      */   }
/*      */   
/*      */   public void setCsrfToken(String csrfToken) {
/*  382 */     this.mCsrfToken = csrfToken;
/*  383 */     if (this.mTransport != null) {
/*  384 */       this.mTransport.setCsrfToken(csrfToken);
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public void soapAdminAuthenticate(String name, String password)
/*      */     throws ServiceException
/*      */   {
/*  396 */     if (this.mTransport == null) { throw ZClientException.CLIENT_ERROR("must call setURI before calling adminAuthenticate", null);
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*  404 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.AUTH_REQUEST);
/*  405 */     req.addElement("name").setText(name);
/*  406 */     req.addElement("password").setText(password);
/*  407 */     Element response = invoke(req);
/*  408 */     this.mAuthToken = new ZAuthToken(response.getElement("authToken"), true);
/*  409 */     this.mAuthTokenLifetime = response.getAttributeLong("lifetime");
/*  410 */     this.mAuthTokenExpiration = (System.currentTimeMillis() + this.mAuthTokenLifetime);
/*  411 */     this.mTransport.setAuthToken(this.mAuthToken);
/*      */   }
/*      */   
/*      */   public void soapAdminAuthenticate(ZAuthToken zat) throws ServiceException
/*      */   {
/*  416 */     if (this.mTransport == null) throw ZClientException.CLIENT_ERROR("must call setURI before calling adminAuthenticate", null);
/*  417 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.AUTH_REQUEST);
/*  418 */     zat.encodeAuthReq(req, true);
/*  419 */     Element response = invoke(req);
/*  420 */     this.mAuthToken = new ZAuthToken(response.getElement("authToken"), true);
/*  421 */     this.mAuthTokenLifetime = response.getAttributeLong("lifetime");
/*  422 */     this.mAuthTokenExpiration = (System.currentTimeMillis() + this.mAuthTokenLifetime);
/*  423 */     this.mTransport.setAuthToken(this.mAuthToken);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public void soapZimbraAdminAuthenticate()
/*      */     throws ServiceException
/*      */   {
/*  435 */     soapAdminAuthenticate(LC.zimbra_ldap_user.value(), LC.zimbra_ldap_password.value());
/*      */   }
/*      */   
/*      */   private String serverName() {
/*      */     try {
/*  440 */       return new java.net.URI(this.mTransport.getURI()).getHost();
/*      */     } catch (java.net.URISyntaxException e) {}
/*  442 */     return this.mTransport.getURI();
/*      */   }
/*      */   
/*      */   private void checkTransport() throws ServiceException
/*      */   {
/*  447 */     if (this.mTransport == null)
/*  448 */       throw ServiceException.FAILURE("transport has not been initialized", null);
/*      */   }
/*      */   
/*      */   private Element invokeRequest(Element request) throws ServiceException, IOException {
/*  452 */     if (this.mNeedSession) {
/*  453 */       return this.mTransport.invoke(request);
/*      */     }
/*  455 */     return this.mTransport.invokeWithoutSession(request);
/*      */   }
/*      */   
/*      */   public synchronized Element invoke(Element request) throws ServiceException
/*      */   {
/*  460 */     checkTransport();
/*      */     try
/*      */     {
/*  463 */       return invokeRequest(request);
/*      */     } catch (SoapFaultException e) {
/*  465 */       throw e;
/*      */     } catch (IOException e) {
/*  467 */       throw ZClientException.IO_ERROR("invoke " + e.getMessage() + ", server: " + serverName(), e);
/*      */     }
/*      */   }
/*      */   
/*      */   protected synchronized Element invokeOnTargetAccount(Element request, String targetId) throws ServiceException {
/*  472 */     checkTransport();
/*      */     
/*  474 */     String oldTarget = this.mTransport.getTargetAcctId();
/*      */     try {
/*  476 */       this.mTransport.setTargetAcctId(targetId);
/*  477 */       return invokeRequest(request);
/*      */     } catch (SoapFaultException e) {
/*  479 */       throw e;
/*      */     } catch (IOException e) {
/*  481 */       throw ZClientException.IO_ERROR("invoke " + e.getMessage() + ", server: " + serverName(), e);
/*      */     } finally {
/*  483 */       this.mTransport.setTargetAcctId(oldTarget);
/*      */     }
/*      */   }
/*      */   
/*      */   synchronized Element invoke(Element request, String serverName) throws ServiceException {
/*  488 */     checkTransport();
/*      */     
/*  490 */     String oldUri = soapGetURI();
/*  491 */     String newUri = com.zimbra.cs.httpclient.URLUtil.getAdminURL(serverName);
/*  492 */     boolean diff = !oldUri.equals(newUri);
/*      */     try {
/*  494 */       if (diff) {
/*  495 */         soapSetURI(newUri);
/*      */       }
/*  497 */       return invokeRequest(request);
/*      */     } catch (SoapFaultException e) {
/*  499 */       throw e;
/*      */     } catch (IOException e) {
/*  501 */       throw ZClientException.IO_ERROR("invoke " + e.getMessage() + ", server: " + serverName, e);
/*      */     } finally {
/*  503 */       if (diff) {
/*  504 */         soapSetURI(oldUri);
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   public <T> T invokeJaxb(Object jaxbObject)
/*      */     throws ServiceException
/*      */   {
/*  512 */     Element req = JaxbUtil.jaxbToElement(jaxbObject);
/*  513 */     Element res = invoke(req);
/*  514 */     return (T)JaxbUtil.elementToJaxb(res);
/*      */   }
/*      */   
/*      */   public <T> T invokeJaxbOnTargetAccount(Object jaxbObject, String targetId)
/*      */     throws ServiceException
/*      */   {
/*  520 */     Element req = JaxbUtil.jaxbToElement(jaxbObject);
/*  521 */     Element res = invokeOnTargetAccount(req, targetId);
/*  522 */     return (T)JaxbUtil.elementToJaxb(res);
/*      */   }
/*      */   
/*      */   public <T> T invokeJaxb(Object jaxbObject, String serverName)
/*      */     throws ServiceException
/*      */   {
/*  528 */     Element req = JaxbUtil.jaxbToElement(jaxbObject);
/*  529 */     Element res = invoke(req, serverName);
/*  530 */     return (T)JaxbUtil.elementToJaxb(res);
/*      */   }
/*      */   
/*      */   public static Map<String, Object> getAttrs(Element e) throws ServiceException {
/*  534 */     return getAttrs(e, "n");
/*      */   }
/*      */   
/*      */   public static Map<String, Object> getAttrs(Element e, String nameAttr) throws ServiceException {
/*  538 */     Map<String, Object> result = new HashMap();
/*  539 */     for (Element a : e.listElements("a")) {
/*  540 */       com.zimbra.common.util.StringUtil.addToMultiMap(result, a.getAttribute(nameAttr), a.getText());
/*      */     }
/*  542 */     return result;
/*      */   }
/*      */   
/*      */   public static void addAttrElements(Element req, Map<String, ? extends Object> attrs) throws ServiceException {
/*  546 */     if (attrs == null) { return;
/*      */     }
/*  548 */     for (Map.Entry<String, ? extends Object> entry : attrs.entrySet()) {
/*  549 */       String key = (String)entry.getKey();
/*  550 */       Object value = entry.getValue();
/*  551 */       if ((value instanceof String)) {
/*  552 */         Element a = req.addElement("a");
/*  553 */         a.addAttribute("n", key);
/*  554 */         a.setText((String)value);
/*  555 */       } else if ((value instanceof String[])) {
/*  556 */         String[] values = (String[])value;
/*  557 */         if (values.length == 0)
/*      */         {
/*  559 */           Element a = req.addElement("a");
/*  560 */           a.addAttribute("n", key);
/*      */         } else {
/*  562 */           for (String v : values) {
/*  563 */             Element a = req.addElement("a");
/*  564 */             a.addAttribute("n", key);
/*  565 */             a.setText(v);
/*      */           }
/*      */         }
/*  568 */       } else if (value == null) {
/*  569 */         Element a = req.addElement("a");
/*  570 */         a.addAttribute("n", key);
/*      */       } else {
/*  572 */         throw ZClientException.CLIENT_ERROR("invalid attr type: " + key + " " + value.getClass().getName(), null);
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   public void addAlias(Account acct, String alias) throws ServiceException
/*      */   {
/*  579 */     invokeJaxb(new com.zimbra.soap.admin.message.AddAccountAliasRequest(acct.getId(), alias));
/*  580 */     reload(acct);
/*      */   }
/*      */   
/*      */   public void addAlias(DistributionList dl, String alias)
/*      */     throws ServiceException
/*      */   {
/*  586 */     invokeJaxb(new com.zimbra.soap.admin.message.AddDistributionListAliasRequest(dl.getId(), alias));
/*  587 */     reload(dl);
/*      */   }
/*      */   
/*      */   public void addGroupAlias(Group group, String alias)
/*      */     throws ServiceException
/*      */   {
/*  593 */     invokeJaxb(new com.zimbra.soap.admin.message.AddDistributionListAliasRequest(group.getId(), alias));
/*  594 */     reload(group);
/*      */   }
/*      */   
/*      */   public void authAccount(Account acct, String password, AuthContext.Protocol proto)
/*      */     throws ServiceException
/*      */   {
/*  600 */     Element.XMLElement req = new Element.XMLElement(AccountConstants.AUTH_REQUEST);
/*  601 */     Element a = req.addElement("account");
/*  602 */     a.addAttribute("by", "name");
/*  603 */     a.setText(acct.getName());
/*  604 */     req.addElement("password").setText(password);
/*  605 */     invoke(req);
/*      */   }
/*      */   
/*      */   public void authAccount(Account acct, String password, AuthContext.Protocol proto, Map<String, Object> context)
/*      */     throws ServiceException
/*      */   {
/*  611 */     authAccount(acct, password, proto);
/*      */   }
/*      */   
/*      */ 
/*      */   public void changePassword(Account acct, String currentPassword, String newPassword)
/*      */     throws ServiceException
/*      */   {
/*  618 */     AccountSelector jaxbAcct = new AccountSelector(AccountBy.name, acct.getName());
/*      */     
/*  620 */     invokeJaxb(new com.zimbra.soap.account.message.ChangePasswordRequest(jaxbAcct, currentPassword, newPassword));
/*      */   }
/*      */   
/*      */ 
/*      */   public Account createAccount(String emailAddress, String password, Map<String, Object> attrs)
/*      */     throws ServiceException
/*      */   {
/*  627 */     CreateAccountResponse resp = (CreateAccountResponse)invokeJaxb(new com.zimbra.soap.admin.message.CreateAccountRequest(emailAddress, password, attrs));
/*      */     
/*  629 */     return new SoapAccount(resp.getAccount(), this);
/*      */   }
/*      */   
/*      */   public Account restoreAccount(String emailAddress, String password, Map<String, Object> attrs, Map<String, Object> origAttrs)
/*      */     throws ServiceException
/*      */   {
/*  635 */     throw new UnsupportedOperationException();
/*      */   }
/*      */   
/*      */   public CalendarResource createCalendarResource(String emailAddress, String password, Map<String, Object> attrs)
/*      */     throws ServiceException
/*      */   {
/*  641 */     CreateCalendarResourceResponse resp = (CreateCalendarResourceResponse)invokeJaxb(new com.zimbra.soap.admin.message.CreateCalendarResourceRequest(emailAddress, password, Attr.mapToList(attrs)));
/*      */     
/*      */ 
/*  644 */     return new SoapCalendarResource(resp.getCalResource(), this);
/*      */   }
/*      */   
/*      */   public Cos createCos(String name, Map<String, Object> attrs)
/*      */     throws ServiceException
/*      */   {
/*  650 */     CreateCosResponse resp = (CreateCosResponse)invokeJaxb(new com.zimbra.soap.admin.message.CreateCosRequest(name, attrs));
/*  651 */     return new SoapCos(resp.getCos(), this);
/*      */   }
/*      */   
/*      */   public Cos copyCos(String srcCosId, String destCosName)
/*      */     throws ServiceException
/*      */   {
/*  657 */     CopyCosResponse resp = (CopyCosResponse)invokeJaxb(new com.zimbra.soap.admin.message.CopyCosRequest(new com.zimbra.soap.admin.type.CosSelector(CosSelector.CosBy.id, srcCosId), destCosName));
/*      */     
/*      */ 
/*  660 */     return new SoapCos(resp.getCos(), this);
/*      */   }
/*      */   
/*      */   public DistributionList createDistributionList(String listAddress, Map<String, Object> listAttrs)
/*      */     throws ServiceException
/*      */   {
/*  666 */     CreateDistributionListRequest req = new CreateDistributionListRequest(listAddress, Attr.mapToList(listAttrs), false);
/*      */     
/*  668 */     CreateDistributionListResponse resp = (CreateDistributionListResponse)invokeJaxb(req);
/*  669 */     return new SoapDistributionList(resp.getDl(), this);
/*      */   }
/*      */   
/*      */   private Group makeGroup(DistributionListInfo dlInfo) throws ServiceException {
/*  673 */     if (dlInfo.isDynamic().booleanValue()) {
/*  674 */       return new SoapDynamicGroup(dlInfo, this);
/*      */     }
/*  676 */     return new SoapDistributionList(dlInfo, this);
/*      */   }
/*      */   
/*      */   private Group makeGroup(DLInfo dlInfo) throws ServiceException
/*      */   {
/*  681 */     if (dlInfo.isDynamic().booleanValue()) {
/*  682 */       return new SoapDynamicGroup(dlInfo, this);
/*      */     }
/*  684 */     return new SoapDistributionList(dlInfo, this);
/*      */   }
/*      */   
/*      */ 
/*      */   public Group createGroup(String listAddress, Map<String, Object> listAttrs, boolean dynamic)
/*      */     throws ServiceException
/*      */   {
/*  691 */     CreateDistributionListRequest req = new CreateDistributionListRequest(listAddress, Attr.mapToList(listAttrs), dynamic);
/*      */     
/*  693 */     CreateDistributionListResponse resp = (CreateDistributionListResponse)invokeJaxb(req);
/*  694 */     return makeGroup(resp.getDl());
/*      */   }
/*      */   
/*      */   public Domain createDomain(String name, Map<String, Object> attrs)
/*      */     throws ServiceException
/*      */   {
/*  700 */     CreateDomainResponse resp = (CreateDomainResponse)invokeJaxb(new com.zimbra.soap.admin.message.CreateDomainRequest(name, attrs));
/*  701 */     return new SoapDomain(resp.getDomain(), this);
/*      */   }
/*      */   
/*      */   public Server createServer(String name, Map<String, Object> attrs)
/*      */     throws ServiceException
/*      */   {
/*  707 */     CreateServerResponse resp = (CreateServerResponse)invokeJaxb(new com.zimbra.soap.admin.message.CreateServerRequest(name, attrs));
/*  708 */     return new SoapServer(resp.getServer(), this);
/*      */   }
/*      */   
/*      */   public AlwaysOnCluster createAlwaysOnCluster(String name, Map<String, Object> attrs)
/*      */     throws ServiceException
/*      */   {
/*  714 */     CreateAlwaysOnClusterResponse resp = (CreateAlwaysOnClusterResponse)invokeJaxb(new com.zimbra.soap.admin.message.CreateAlwaysOnClusterRequest(name, attrs));
/*  715 */     return new SoapAlwaysOnCluster(resp.getAlwaysOnCluster(), this);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   public Zimlet createZimlet(String name, Map<String, Object> attrs)
/*      */     throws ServiceException
/*      */   {
/*  724 */     throw new UnsupportedOperationException();
/*      */   }
/*      */   
/*      */   public void deleteAccount(String zimbraId) throws ServiceException
/*      */   {
/*  729 */     invokeJaxb(new com.zimbra.soap.admin.message.DeleteAccountRequest(zimbraId));
/*      */   }
/*      */   
/*      */   public void deleteCalendarResource(String zimbraId) throws ServiceException
/*      */   {
/*  734 */     invokeJaxb(new com.zimbra.soap.admin.message.DeleteCalendarResourceRequest(zimbraId));
/*      */   }
/*      */   
/*      */   public void deleteCos(String zimbraId) throws ServiceException
/*      */   {
/*  739 */     invokeJaxb(new com.zimbra.soap.admin.message.DeleteCosRequest(zimbraId));
/*      */   }
/*      */   
/*      */   public void deleteDistributionList(String zimbraId) throws ServiceException
/*      */   {
/*  744 */     invokeJaxb(new com.zimbra.soap.admin.message.DeleteDistributionListRequest(zimbraId));
/*      */   }
/*      */   
/*      */   public void deleteGroup(String zimbraId) throws ServiceException
/*      */   {
/*  749 */     invokeJaxb(new com.zimbra.soap.admin.message.DeleteDistributionListRequest(zimbraId));
/*      */   }
/*      */   
/*      */   public void deleteDomain(String zimbraId) throws ServiceException
/*      */   {
/*  754 */     invokeJaxb(new com.zimbra.soap.admin.message.DeleteDomainRequest(zimbraId));
/*      */   }
/*      */   
/*      */   public void deleteServer(String zimbraId) throws ServiceException
/*      */   {
/*  759 */     invokeJaxb(new com.zimbra.soap.admin.message.DeleteServerRequest(zimbraId));
/*      */   }
/*      */   
/*      */   public void deleteAlwaysOnCluster(String zimbraId) throws ServiceException
/*      */   {
/*  764 */     invokeJaxb(new com.zimbra.soap.admin.message.DeleteAlwaysOnClusterRequest(zimbraId));
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public void deleteZimlet(String name)
/*      */     throws ServiceException
/*      */   {
/*  772 */     throw new UnsupportedOperationException();
/*      */   }
/*      */   
/*      */   public static class DelegateAuthResponse
/*      */   {
/*      */     private final ZAuthToken mAuthToken;
/*      */     private final long mExpires;
/*      */     private final long mLifetime;
/*      */     
/*      */     DelegateAuthResponse(Element e) throws ServiceException {
/*  782 */       this.mAuthToken = new ZAuthToken(e.getElement("authToken"), false);
/*  783 */       this.mLifetime = e.getAttributeLong("lifetime");
/*  784 */       this.mExpires = (System.currentTimeMillis() + this.mLifetime);
/*  785 */       Element re = e.getOptionalElement("refer");
/*      */     }
/*      */     
/*      */     public ZAuthToken getAuthToken() {
/*  789 */       return this.mAuthToken;
/*      */     }
/*      */     
/*      */     public long getExpires() {
/*  793 */       return this.mExpires;
/*      */     }
/*      */     
/*      */     public long getLifetime() {
/*  797 */       return this.mLifetime;
/*      */     }
/*      */   }
/*      */   
/*      */   public DelegateAuthResponse delegateAuth(Key.AccountBy keyType, String key, int durationSeconds) throws ServiceException {
/*  802 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.DELEGATE_AUTH_REQUEST);
/*  803 */     req.addAttribute("duration", durationSeconds);
/*  804 */     Element acct = req.addElement("account");
/*  805 */     acct.addAttribute("by", keyType.name());
/*  806 */     acct.setText(key);
/*  807 */     return new DelegateAuthResponse(invoke(req));
/*      */   }
/*      */   
/*      */   public SoapAccountInfo getAccountInfo(Key.AccountBy keyType, String key) throws ServiceException
/*      */   {
/*  812 */     com.zimbra.soap.admin.message.GetAccountInfoResponse resp = (com.zimbra.soap.admin.message.GetAccountInfoResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetAccountInfoRequest(new AccountSelector(toJaxb(keyType), key)));
/*      */     
/*  814 */     return new SoapAccountInfo(resp);
/*      */   }
/*      */   
/*      */   public Account get(Key.AccountBy keyType, String key) throws ServiceException
/*      */   {
/*  819 */     return get(keyType, key, true);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public Account getAccount(String key, boolean applyDefault)
/*      */     throws ServiceException
/*      */   {
/*  830 */     Account acct = null;
/*      */     
/*  832 */     if (com.zimbra.cs.account.Provisioning.isUUID(key)) {
/*  833 */       acct = get(Key.AccountBy.id, key, applyDefault);
/*      */     }
/*      */     else {
/*  836 */       acct = get(Key.AccountBy.name, key, applyDefault);
/*  837 */       if (acct == null) {
/*  838 */         acct = get(Key.AccountBy.id, key, applyDefault);
/*      */       }
/*      */     }
/*  841 */     return acct;
/*      */   }
/*      */   
/*      */   public Account get(Key.AccountBy keyType, String key, boolean applyDefault)
/*      */     throws ServiceException
/*      */   {
/*      */     try
/*      */     {
/*  849 */       GetAccountResponse resp = (GetAccountResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetAccountRequest(new AccountSelector(toJaxb(keyType), key), Boolean.valueOf(applyDefault)));
/*      */       
/*      */ 
/*  852 */       return new SoapAccount(resp.getAccount(), this);
/*      */     } catch (ServiceException e) {
/*  854 */       if (e.getCode().equals("account.NO_SUCH_ACCOUNT")) {
/*  855 */         return null;
/*      */       }
/*  857 */       throw e;
/*      */     }
/*      */   }
/*      */   
/*      */   public List<Account> getAllAdminAccounts() throws ServiceException
/*      */   {
/*  863 */     return getAllAdminAccounts(true);
/*      */   }
/*      */   
/*      */   public List<Account> getAllAdminAccounts(boolean applyDefault) throws ServiceException
/*      */   {
/*  868 */     ArrayList<Account> result = new ArrayList();
/*  869 */     GetAllAdminAccountsResponse resp = (GetAllAdminAccountsResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetAllAdminAccountsRequest(Boolean.valueOf(applyDefault)));
/*      */     
/*  871 */     for (AccountInfo acct : resp.getAccountList()) {
/*  872 */       result.add(new SoapAccount(acct, this));
/*      */     }
/*  874 */     return result;
/*      */   }
/*      */   
/*      */   public List<Cos> getAllCos() throws ServiceException
/*      */   {
/*  879 */     ArrayList<Cos> result = new ArrayList();
/*  880 */     GetAllCosResponse resp = (GetAllCosResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetAllCosRequest());
/*  881 */     for (com.zimbra.soap.admin.type.CosInfo cosInfo : resp.getCosList()) {
/*  882 */       result.add(new SoapCos(cosInfo, this));
/*      */     }
/*  884 */     return result;
/*      */   }
/*      */   
/*      */   public List<Domain> getAllDomains() throws ServiceException
/*      */   {
/*  889 */     return getAllDomains(true);
/*      */   }
/*      */   
/*      */   public List<Domain> getAllDomains(boolean applyDefault)
/*      */     throws ServiceException
/*      */   {
/*  895 */     ArrayList<Domain> result = new ArrayList();
/*  896 */     GetAllDomainsResponse resp = (GetAllDomainsResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetAllDomainsRequest(Boolean.valueOf(applyDefault)));
/*      */     
/*  898 */     for (DomainInfo domainInfo : resp.getDomainList()) {
/*  899 */       result.add(new SoapDomain(domainInfo, this));
/*      */     }
/*  901 */     return result;
/*      */   }
/*      */   
/*      */   public List<Server> getAllServers() throws ServiceException
/*      */   {
/*  906 */     return getAllServers(null, true);
/*      */   }
/*      */   
/*      */   public List<AlwaysOnCluster> getAllAlwaysOnClusters() throws ServiceException
/*      */   {
/*  911 */     ArrayList<AlwaysOnCluster> result = new ArrayList();
/*  912 */     GetAllAlwaysOnClustersResponse resp = (GetAllAlwaysOnClustersResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetAllAlwaysOnClustersRequest());
/*      */     
/*  914 */     for (com.zimbra.soap.admin.type.AlwaysOnClusterInfo clusterInfo : resp.getAlwaysOnClusterList()) {
/*  915 */       result.add(new SoapAlwaysOnCluster(clusterInfo, this));
/*      */     }
/*  917 */     return result;
/*      */   }
/*      */   
/*      */   public List<Server> getAllActiveServers() throws ServiceException {
/*  921 */     List<Server> result = new ArrayList();
/*  922 */     GetAllActiveServersResponse resp = (GetAllActiveServersResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetAllActiveServersRequest());
/*      */     
/*  924 */     for (ServerInfo serverInfo : resp.getServerList()) {
/*  925 */       result.add(new SoapServer(serverInfo, this));
/*      */     }
/*  927 */     return result;
/*      */   }
/*      */   
/*      */   public void setServerOffline(Key.ServerBy keyType, String key) throws ServiceException {
/*  931 */     ServerSelector sel = new ServerSelector(toJaxb(keyType), key);
/*      */     
/*  933 */     invokeJaxb(new com.zimbra.soap.admin.message.SetServerOfflineRequest(sel));
/*      */   }
/*      */   
/*      */   public void setLocalServerOnline() throws ServiceException {
/*  937 */     invokeJaxb(new com.zimbra.soap.admin.message.SetLocalServerOnlineRequest());
/*      */   }
/*      */   
/*      */   public static class QuotaUsage {
/*      */     public String mName;
/*      */     public String mId;
/*      */     long mUsed;
/*      */     long mLimit;
/*      */     
/*  946 */     public String getName() { return this.mName; }
/*  947 */     public String getId() { return this.mId; }
/*  948 */     public long getUsed() { return this.mUsed; }
/*  949 */     public long getLimit() { return this.mLimit; }
/*      */     
/*      */     QuotaUsage(AccountQuotaInfo quotaInfo) {
/*  952 */       this.mName = quotaInfo.getName();
/*  953 */       this.mId = quotaInfo.getId();
/*  954 */       this.mUsed = quotaInfo.getQuotaUsed();
/*  955 */       this.mLimit = quotaInfo.getQuotaLimit();
/*      */     }
/*      */   }
/*      */   
/*      */   public List<QuotaUsage> getQuotaUsage(String server) throws ServiceException {
/*  960 */     ArrayList<QuotaUsage> result = new ArrayList();
/*  961 */     GetQuotaUsageResponse resp = (GetQuotaUsageResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetQuotaUsageRequest(), server);
/*      */     
/*  963 */     for (AccountQuotaInfo quotaInfo : resp.getAccountQuotas()) {
/*  964 */       result.add(new QuotaUsage(quotaInfo));
/*      */     }
/*  966 */     return result;
/*      */   }
/*      */   
/*      */   public List<AccountLogger> addAccountLogger(Account account, String category, String level, String serverName)
/*      */     throws ServiceException
/*      */   {
/*  972 */     if (serverName == null) {
/*  973 */       serverName = account.getServerName();
/*      */     }
/*  975 */     LoggerInfo logger = LoggerInfo.createForCategoryAndLevelString(category, level);
/*  976 */     com.zimbra.soap.admin.message.AddAccountLoggerRequest req = com.zimbra.soap.admin.message.AddAccountLoggerRequest.createForAccountAndLogger(getSelector(account), logger);
/*      */     
/*  978 */     AddAccountLoggerResponse resp = serverName == null ? (AddAccountLoggerResponse)invokeJaxb(req) : (AddAccountLoggerResponse)invokeJaxb(req, serverName);
/*      */     
/*      */ 
/*  981 */     return accountLoggersFromLoggerInfos(resp.getLoggers(), account.getName());
/*      */   }
/*      */   
/*      */ 
/*      */   private AccountLogger accountLoggerFromLoggerInfo(LoggerInfo loggerInfo, String accountName)
/*      */   {
/*  987 */     return new AccountLogger(loggerInfo.getCategory(), accountName, com.zimbra.common.util.Log.Level.valueOf(loggerInfo.getLevel().toString()));
/*      */   }
/*      */   
/*      */ 
/*      */   private List<AccountLogger> accountLoggersFromLoggerInfos(List<LoggerInfo> loggerInfos, String accountName)
/*      */   {
/*  993 */     List<AccountLogger> loggers = com.google.common.collect.Lists.newArrayList();
/*  994 */     for (LoggerInfo loggerInfo : loggerInfos) {
/*  995 */       loggers.add(accountLoggerFromLoggerInfo(loggerInfo, accountName));
/*      */     }
/*  997 */     return loggers;
/*      */   }
/*      */   
/*      */   public List<AccountLogger> getAccountLoggers(Account account, String serverName) throws ServiceException
/*      */   {
/* 1002 */     if (serverName == null) {
/* 1003 */       serverName = account.getServerName();
/*      */     }
/*      */     
/* 1006 */     com.zimbra.soap.admin.message.GetAccountLoggersRequest req = new com.zimbra.soap.admin.message.GetAccountLoggersRequest(getSelector(account));
/*      */     
/* 1008 */     GetAccountLoggersResponse resp = serverName == null ? (GetAccountLoggersResponse)invokeJaxb(req) : (GetAccountLoggersResponse)invokeJaxb(req, serverName);
/*      */     
/*      */ 
/* 1011 */     return accountLoggersFromLoggerInfos(resp.getLoggers(), account.getName());
/*      */   }
/*      */   
/*      */ 
/*      */   private SoapTransport.DebugListener mDebugListener;
/*      */   private SoapHttpTransport.HttpDebugListener mHttpDebugListener;
/*      */   private final boolean mNeedSession;
/*      */   private static final String DATA_DL_SET = "DL_SET";
/*      */   private static final String DATA_DIRECT_DL_SET = "DIRECT_DL_SET";
/*      */   private static final String DATA_GROUP_SET = "GROUP_SET";
/*      */   public Map<String, List<AccountLogger>> getAllAccountLoggers(String server)
/*      */     throws ServiceException
/*      */   {
/* 1024 */     if (server == null) {
/* 1025 */       server = getLocalServer().getName();
/*      */     }
/* 1027 */     GetAllAccountLoggersResponse resp = (GetAllAccountLoggersResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetAllAccountLoggersRequest(), server);
/*      */     
/* 1029 */     Map<String, List<AccountLogger>> result = new HashMap();
/*      */     
/* 1031 */     for (AccountLoggerInfo acctLogger : resp.getLoggers()) {
/* 1032 */       String acctName = acctLogger.getName();
/* 1033 */       result.put(acctName, accountLoggersFromLoggerInfos(acctLogger.getLoggers(), acctName));
/*      */     }
/*      */     
/* 1036 */     return result;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public void removeAccountLoggers(Account account, String category, String serverName)
/*      */     throws ServiceException
/*      */   {
/* 1048 */     if (serverName == null) {
/* 1049 */       if (account == null) {
/* 1050 */         serverName = getLocalServer().getName();
/*      */       } else {
/* 1052 */         serverName = account.getServerName();
/*      */       }
/*      */     }
/* 1055 */     LoggerInfo logger = null;
/* 1056 */     if (category != null) {
/* 1057 */       logger = LoggerInfo.createForCategoryAndLevel(category, null);
/*      */     }
/*      */     
/* 1060 */     com.zimbra.soap.admin.message.RemoveAccountLoggerRequest req = new com.zimbra.soap.admin.message.RemoveAccountLoggerRequest(getSelector(account), logger);
/*      */     
/*      */ 
/* 1063 */     RemoveAccountLoggerResponse resp = serverName == null ? (RemoveAccountLoggerResponse)invokeJaxb(req) : (RemoveAccountLoggerResponse)invokeJaxb(req, serverName);
/*      */   }
/*      */   
/*      */   public void resetAllLoggers(String server)
/*      */     throws ServiceException
/*      */   {
/* 1069 */     invokeJaxb(new com.zimbra.soap.admin.message.ResetAllLoggersRequest(), server != null ? server : getLocalServer().getName());
/*      */   }
/*      */   
/*      */   public static class MailboxInfo {
/*      */     private final long mUsed;
/*      */     private final String mMboxId;
/*      */     
/* 1076 */     public long getUsed() { return this.mUsed; }
/* 1077 */     public String getMailboxId() { return this.mMboxId; }
/*      */     
/*      */     public MailboxInfo(MailboxWithMailboxId jaxbMboxInfo) {
/* 1080 */       this.mMboxId = Integer.toString(jaxbMboxInfo.getMbxid());
/* 1081 */       this.mUsed = jaxbMboxInfo.getSize().longValue();
/*      */     }
/*      */     
/*      */     public MailboxInfo(String id, long used) {
/* 1085 */       this.mMboxId = id;
/* 1086 */       this.mUsed = used;
/*      */     }
/*      */   }
/*      */   
/*      */   public MailboxInfo getMailbox(Account acct) throws ServiceException {
/* 1091 */     Server server = getServer(acct);
/* 1092 */     String serviceHost = server.getAttr("zimbraServiceHostname");
/* 1093 */     MailboxByAccountIdSelector mbox = new MailboxByAccountIdSelector(acct.getId());
/*      */     
/* 1095 */     GetMailboxResponse resp = (GetMailboxResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetMailboxRequest(mbox), serviceHost);
/* 1096 */     resp.getMbox();
/* 1097 */     return new MailboxInfo(resp.getMbox());
/*      */   }
/*      */   
/*      */   public static enum ReIndexBy {
/* 1101 */     types,  ids;
/*      */     
/*      */     private ReIndexBy() {}
/*      */   }
/*      */   
/*      */   public static final class ReIndexInfo { private final String status;
/*      */     private final Progress progress;
/*      */     
/* 1109 */     public String getStatus() { return this.status; }
/*      */     
/*      */     public Progress getProgress()
/*      */     {
/* 1113 */       return this.progress;
/*      */     }
/*      */     
/*      */     ReIndexInfo(String status, Progress progress) {
/* 1117 */       this.status = status;
/* 1118 */       this.progress = progress;
/*      */     }
/*      */     
/*      */     public static final class Progress {
/*      */       private long numSucceeded;
/*      */       private long numFailed;
/*      */       private long numRemaining;
/*      */       
/*      */       public long getNumSucceeded() {
/* 1127 */         return this.numSucceeded;
/*      */       }
/*      */       
/*      */       public long getNumFailed() {
/* 1131 */         return this.numFailed;
/*      */       }
/*      */       
/*      */       public long getNumRemaining() {
/* 1135 */         return this.numRemaining;
/*      */       }
/*      */       
/*      */       Progress() {}
/*      */       
/*      */       Progress(long succeeded, long failed, long remaining)
/*      */       {
/* 1142 */         this.numSucceeded = succeeded;
/* 1143 */         this.numFailed = failed;
/* 1144 */         this.numRemaining = remaining;
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */   public ReIndexInfo reIndex(Account acct, String action, ReIndexBy by, String[] values)
/*      */     throws ServiceException
/*      */   {
/* 1152 */     Server server = getServer(acct);
/* 1153 */     ReindexMailboxInfo mbox = new ReindexMailboxInfo(acct.getId());
/* 1154 */     if (by != null) {
/* 1155 */       String vals = com.zimbra.common.util.StringUtil.join(",", values);
/* 1156 */       if (by == ReIndexBy.types) {
/* 1157 */         mbox.setTypes(vals);
/*      */       } else {
/* 1159 */         mbox.setIds(vals);
/*      */       }
/*      */     }
/* 1162 */     com.zimbra.soap.admin.message.ReIndexRequest req = new com.zimbra.soap.admin.message.ReIndexRequest(action, mbox);
/* 1163 */     ReIndexResponse resp = (ReIndexResponse)invokeJaxb(req, server.getAttr("zimbraServiceHostname"));
/*      */     
/* 1165 */     SoapProvisioning.ReIndexInfo.Progress progress = null;
/* 1166 */     ReindexProgressInfo progInfo = resp.getProgress();
/* 1167 */     if (progInfo != null) {
/* 1168 */       progress = new SoapProvisioning.ReIndexInfo.Progress(progInfo.getNumSucceeded(), progInfo.getNumFailed(), progInfo.getNumRemaining());
/*      */     }
/*      */     
/*      */ 
/* 1172 */     return new ReIndexInfo(resp.getStatus(), progress);
/*      */   }
/*      */   
/*      */   public String compactIndex(Account acct, String action) throws ServiceException
/*      */   {
/* 1177 */     Server server = getServer(acct);
/* 1178 */     com.zimbra.soap.admin.message.CompactIndexRequest req = new com.zimbra.soap.admin.message.CompactIndexRequest(action, new MailboxByAccountIdSelector(acct.getId()));
/* 1179 */     CompactIndexResponse resp = (CompactIndexResponse)invokeJaxb(req, server.getAttr("zimbraServiceHostname"));
/*      */     
/* 1181 */     return resp.getStatus();
/*      */   }
/*      */   
/*      */   public static final class IndexStatsInfo {
/*      */     private final int maxDocs;
/*      */     private final int numDeletedDocs;
/*      */     
/*      */     public IndexStatsInfo(int maxDocs, int numDeletedDocs) {
/* 1189 */       this.maxDocs = maxDocs;
/* 1190 */       this.numDeletedDocs = numDeletedDocs;
/*      */     }
/*      */     
/*      */     public int getMaxDocs() {
/* 1194 */       return this.maxDocs;
/*      */     }
/*      */     
/*      */     public int getNumDeletedDocs() {
/* 1198 */       return this.numDeletedDocs;
/*      */     }
/*      */   }
/*      */   
/*      */   public IndexStatsInfo getIndexStats(Account acct) throws ServiceException
/*      */   {
/* 1204 */     Server server = getServer(acct);
/* 1205 */     com.zimbra.soap.admin.message.GetIndexStatsRequest req = new com.zimbra.soap.admin.message.GetIndexStatsRequest(new MailboxByAccountIdSelector(acct.getId()));
/* 1206 */     GetIndexStatsResponse resp = (GetIndexStatsResponse)invokeJaxb(req, server.getAttr("zimbraServiceHostname"));
/*      */     
/* 1208 */     return new IndexStatsInfo(resp.getStats().getMaxDocs(), resp.getStats().getNumDeletedDocs());
/*      */   }
/*      */   
/*      */   public static final class VerifyIndexResult {
/*      */     public final boolean status;
/*      */     public final String message;
/*      */     
/*      */     VerifyIndexResult(boolean status, String message) {
/* 1216 */       this.status = status;
/* 1217 */       this.message = message;
/*      */     }
/*      */   }
/*      */   
/*      */   public VerifyIndexResult verifyIndex(Account account) throws ServiceException {
/* 1222 */     com.zimbra.soap.admin.message.VerifyIndexRequest req = new com.zimbra.soap.admin.message.VerifyIndexRequest(new MailboxByAccountIdSelector(account.getId()));
/*      */     
/* 1224 */     VerifyIndexResponse resp = (VerifyIndexResponse)invokeJaxb(req, getServer(account).getAttr("zimbraServiceHostname"));
/*      */     
/* 1226 */     return new VerifyIndexResult(resp.isStatus(), resp.getMessage());
/*      */   }
/*      */   
/*      */   public long recalculateMailboxCounts(Account acct) throws ServiceException {
/* 1230 */     String hostname = getServer(acct).getServiceHostname();
/* 1231 */     MailboxByAccountIdSelector mbox = new MailboxByAccountIdSelector(acct.getId());
/* 1232 */     RecalculateMailboxCountsResponse resp = (RecalculateMailboxCountsResponse)invokeJaxb(new com.zimbra.soap.admin.message.RecalculateMailboxCountsRequest(mbox), hostname);
/* 1233 */     return resp.getMailbox().getQuotaUsed();
/*      */   }
/*      */   
/*      */   public List<Server> getAllServers(String service) throws ServiceException
/*      */   {
/* 1238 */     return getAllServers(service, true);
/*      */   }
/*      */   
/*      */   public List<Server> getAllServers(String service, boolean applyDefault)
/*      */     throws ServiceException
/*      */   {
/* 1244 */     ArrayList<Server> result = new ArrayList();
/* 1245 */     GetAllServersResponse resp = (GetAllServersResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetAllServersRequest(service, Boolean.valueOf(applyDefault)));
/*      */     
/* 1247 */     for (ServerInfo serverInfo : resp.getServerList()) {
/* 1248 */       result.add(new SoapServer(serverInfo, this));
/*      */     }
/* 1250 */     return result;
/*      */   }
/*      */   
/*      */   public CalendarResource get(Key.CalendarResourceBy keyType, String key) throws ServiceException
/*      */   {
/*      */     try {
/* 1256 */       com.zimbra.soap.admin.message.GetCalendarResourceRequest req = new com.zimbra.soap.admin.message.GetCalendarResourceRequest(new com.zimbra.soap.admin.type.CalendarResourceSelector(toJaxb(keyType), key));
/*      */       
/*      */ 
/*      */ 
/* 1260 */       GetCalendarResourceResponse resp = (GetCalendarResourceResponse)invokeJaxb(req);
/* 1261 */       return new SoapCalendarResource(resp.getCalResource(), this);
/*      */     } catch (ServiceException e) {
/* 1263 */       if (e.getCode().equals("account.NO_SUCH_CALENDAR_RESOURCE")) {
/* 1264 */         return null;
/*      */       }
/* 1266 */       throw e;
/*      */     }
/*      */   }
/*      */   
/*      */   public com.zimbra.cs.account.Config getConfig() throws ServiceException
/*      */   {
/* 1272 */     com.zimbra.soap.admin.message.GetAllConfigResponse resp = (com.zimbra.soap.admin.message.GetAllConfigResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetAllConfigRequest());
/* 1273 */     return new SoapConfig(resp, this);
/*      */   }
/*      */   
/*      */   public com.zimbra.cs.account.Config getConfig(String needAttr) throws ServiceException
/*      */   {
/* 1278 */     GetConfigRequest req = new GetConfigRequest();
/* 1279 */     Attr attr = new Attr();
/* 1280 */     attr.setKey(needAttr);
/* 1281 */     req.setAttr(attr);
/* 1282 */     com.zimbra.soap.admin.message.GetConfigResponse resp = (com.zimbra.soap.admin.message.GetConfigResponse)invokeJaxb(req);
/* 1283 */     return new SoapConfig(resp, this);
/*      */   }
/*      */   
/*      */   public com.zimbra.cs.account.GlobalGrant getGlobalGrant() throws ServiceException
/*      */   {
/* 1288 */     throw ServiceException.FAILURE("not supported", null);
/*      */   }
/*      */   
/*      */   public Cos get(Key.CosBy keyType, String key) throws ServiceException
/*      */   {
/*      */     try {
/* 1294 */       GetCosResponse resp = (GetCosResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetCosRequest(new com.zimbra.soap.admin.type.CosSelector(toJaxb(keyType), key)));
/*      */       
/* 1296 */       return new SoapCos(resp.getCos(), this);
/*      */     } catch (ServiceException e) {
/* 1298 */       if (e.getCode().equals("account.NO_SUCH_COS")) {
/* 1299 */         return null;
/*      */       }
/* 1301 */       throw e;
/*      */     }
/*      */   }
/*      */   
/*      */   public DistributionList get(Key.DistributionListBy keyType, String key) throws ServiceException
/*      */   {
/*      */     try {
/* 1308 */       GetDistributionListResponse resp = (GetDistributionListResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetDistributionListRequest(new com.zimbra.soap.admin.type.DistributionListSelector(toJaxb(keyType), key)));
/*      */       
/* 1310 */       return new SoapDistributionList(resp.getDl(), this);
/*      */     } catch (ServiceException e) {
/* 1312 */       if (e.getCode().equals("account.NO_SUCH_DISTRIBUTION_LIST")) {
/* 1313 */         return null;
/*      */       }
/* 1315 */       throw e;
/*      */     }
/*      */   }
/*      */   
/*      */   public Group getGroup(Key.DistributionListBy keyType, String key) throws ServiceException
/*      */   {
/*      */     try {
/* 1322 */       GetDistributionListResponse resp = (GetDistributionListResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetDistributionListRequest(new com.zimbra.soap.admin.type.DistributionListSelector(toJaxb(keyType), key)));
/*      */       
/* 1324 */       return makeGroup(resp.getDl());
/*      */     } catch (ServiceException e) {
/* 1326 */       if (e.getCode().equals("account.NO_SUCH_DISTRIBUTION_LIST")) {
/* 1327 */         return null;
/*      */       }
/* 1329 */       throw e;
/*      */     }
/*      */   }
/*      */   
/*      */   public Domain getDomainInfo(Key.DomainBy keyType, String key) throws ServiceException
/*      */   {
/* 1335 */     DomainSelector domSel = new DomainSelector(toJaxb(keyType), key);
/*      */     try
/*      */     {
/* 1338 */       GetDomainInfoResponse resp = (GetDomainInfoResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetDomainInfoRequest(domSel, null));
/*      */       
/* 1340 */       DomainInfo domainInfo = resp.getDomain();
/* 1341 */       return domainInfo == null ? null : new SoapDomain(domainInfo, this);
/*      */     } catch (ServiceException e) {
/* 1343 */       if (e.getCode().equals("account.NO_SUCH_DOMAIN")) {
/* 1344 */         return null;
/*      */       }
/* 1346 */       throw e;
/*      */     }
/*      */   }
/*      */   
/*      */   public Domain get(Key.DomainBy keyType, String key) throws ServiceException
/*      */   {
/* 1352 */     return get(keyType, key, true);
/*      */   }
/*      */   
/*      */   public Domain get(Key.DomainBy keyType, String key, boolean applyDefault)
/*      */     throws ServiceException
/*      */   {
/* 1358 */     DomainSelector domSel = new DomainSelector(toJaxb(keyType), key);
/*      */     try
/*      */     {
/* 1361 */       GetDomainResponse resp = (GetDomainResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetDomainRequest(domSel, Boolean.valueOf(applyDefault)));
/*      */       
/* 1363 */       return new SoapDomain(resp.getDomain(), this);
/*      */     } catch (ServiceException e) {
/* 1365 */       if (e.getCode().equals("account.NO_SUCH_DOMAIN")) {
/* 1366 */         return null;
/*      */       }
/* 1368 */       throw e;
/*      */     }
/*      */   }
/*      */   
/*      */   public Server getLocalServer() throws ServiceException
/*      */   {
/* 1374 */     String hostname = LC.zimbra_server_hostname.value();
/* 1375 */     if (hostname == null)
/* 1376 */       throw ServiceException.FAILURE("zimbra_server_hostname not specified in localconfig.xml", null);
/* 1377 */     Server local = get(Key.ServerBy.name, hostname);
/* 1378 */     if (local == null)
/* 1379 */       throw ServiceException.FAILURE("Could not find an LDAP entry for server '" + hostname + "'", null);
/* 1380 */     return local;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public List<com.zimbra.cs.mime.MimeTypeInfo> getMimeTypes(String name)
/*      */     throws ServiceException
/*      */   {
/* 1388 */     throw new UnsupportedOperationException();
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   public List<com.zimbra.cs.mime.MimeTypeInfo> getAllMimeTypes()
/*      */     throws ServiceException
/*      */   {
/* 1397 */     throw new UnsupportedOperationException();
/*      */   }
/*      */   
/*      */   public Server get(Key.ServerBy keyType, String key) throws ServiceException
/*      */   {
/* 1402 */     return get(keyType, key, true);
/*      */   }
/*      */   
/*      */   public Server get(Key.ServerBy keyType, String key, boolean applyDefault)
/*      */     throws ServiceException
/*      */   {
/* 1408 */     ServerSelector sel = new ServerSelector(toJaxb(keyType), key);
/*      */     try
/*      */     {
/* 1411 */       GetServerResponse resp = (GetServerResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetServerRequest(sel, Boolean.valueOf(applyDefault)));
/*      */       
/* 1413 */       return new SoapServer(resp.getServer(), this);
/*      */     } catch (ServiceException e) {
/* 1415 */       if (e.getCode().equals("account.NO_SUCH_SERVER")) {
/* 1416 */         return null;
/*      */       }
/* 1418 */       throw e;
/*      */     }
/*      */   }
/*      */   
/*      */   public AlwaysOnCluster get(Key.AlwaysOnClusterBy keyType, String key) throws ServiceException
/*      */   {
/* 1424 */     com.zimbra.soap.admin.type.AlwaysOnClusterSelector sel = new com.zimbra.soap.admin.type.AlwaysOnClusterSelector(toJaxb(keyType), key);
/*      */     try
/*      */     {
/* 1427 */       GetAlwaysOnClusterResponse resp = (GetAlwaysOnClusterResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetAlwaysOnClusterRequest(sel));
/*      */       
/* 1429 */       return new SoapAlwaysOnCluster(resp.getAlwaysOnCluster(), this);
/*      */     } catch (ServiceException e) {
/* 1431 */       if (e.getCode().equals("account.NO_SUCH_ALWAYSONCLUSTER")) {
/* 1432 */         return null;
/*      */       }
/* 1434 */       throw e;
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public Zimlet getZimlet(String name)
/*      */     throws ServiceException
/*      */   {
/* 1443 */     throw new UnsupportedOperationException();
/*      */   }
/*      */   
/*      */   public boolean healthCheck() throws ServiceException
/*      */   {
/* 1448 */     CheckHealthResponse resp = (CheckHealthResponse)invokeJaxb(new com.zimbra.soap.admin.message.CheckHealthRequest());
/* 1449 */     return resp.isHealthy();
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public List<Zimlet> listAllZimlets()
/*      */     throws ServiceException
/*      */   {
/* 1457 */     throw new UnsupportedOperationException();
/*      */   }
/*      */   
/*      */   public void modifyAccountStatus(Account acct, String newStatus)
/*      */     throws ServiceException
/*      */   {
/* 1463 */     HashMap<String, String> attrs = new HashMap();
/* 1464 */     attrs.put("zimbraAccountStatus", newStatus);
/* 1465 */     modifyAttrs(acct, attrs);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public void preAuthAccount(Account acct, String accountName, String accountBy, long timestamp, long expires, String preAuth, Map<String, Object> authCtxt)
/*      */     throws ServiceException
/*      */   {
/* 1473 */     Element.XMLElement req = new Element.XMLElement(AccountConstants.AUTH_REQUEST);
/* 1474 */     Element a = req.addElement("account");
/* 1475 */     a.addAttribute("by", "name");
/* 1476 */     a.setText(accountName);
/* 1477 */     Element p = req.addElement("preauth");
/* 1478 */     p.addAttribute("timestamp", timestamp);
/* 1479 */     p.addAttribute("by", accountBy);
/* 1480 */     p.addAttribute("expires", expires);
/* 1481 */     p.setText(preAuth);
/* 1482 */     invoke(req);
/*      */   }
/*      */   
/*      */   public void ssoAuthAccount(Account acct, AuthContext.Protocol proto, Map<String, Object> authCtxt)
/*      */     throws ServiceException
/*      */   {
/* 1488 */     throw new UnsupportedOperationException();
/*      */   }
/*      */   
/*      */   public void removeAlias(Account acct, String alias) throws ServiceException
/*      */   {
/* 1493 */     invokeJaxb(new com.zimbra.soap.admin.message.RemoveAccountAliasRequest(acct == null ? null : acct.getId(), alias));
/*      */     
/* 1495 */     if (acct != null) {
/* 1496 */       reload(acct);
/*      */     }
/*      */   }
/*      */   
/*      */   public void removeAlias(DistributionList dl, String alias) throws ServiceException
/*      */   {
/* 1502 */     invokeJaxb(new RemoveDistributionListAliasRequest(dl == null ? null : dl.getId(), alias));
/*      */     
/* 1504 */     if (dl != null) {
/* 1505 */       reload(dl);
/*      */     }
/*      */   }
/*      */   
/*      */   public void removeGroupAlias(Group group, String alias) throws ServiceException
/*      */   {
/* 1511 */     invokeJaxb(new RemoveDistributionListAliasRequest(group == null ? null : group.getId(), alias));
/*      */     
/* 1513 */     if (group != null) {
/* 1514 */       reload(group);
/*      */     }
/*      */   }
/*      */   
/*      */   public void renameAccount(String zimbraId, String newName) throws ServiceException
/*      */   {
/* 1520 */     invokeJaxb(new com.zimbra.soap.admin.message.RenameAccountRequest(zimbraId, newName));
/*      */   }
/*      */   
/*      */   public void renameCalendarResource(String zimbraId, String newName)
/*      */     throws ServiceException
/*      */   {
/* 1526 */     invokeJaxb(new com.zimbra.soap.admin.message.RenameCalendarResourceRequest(zimbraId, newName));
/*      */   }
/*      */   
/*      */   public void renameCos(String zimbraId, String newName)
/*      */     throws ServiceException
/*      */   {
/* 1532 */     invokeJaxb(new com.zimbra.soap.admin.message.RenameCosRequest(zimbraId, newName));
/*      */   }
/*      */   
/*      */   public void renameDistributionList(String zimbraId, String newName)
/*      */     throws ServiceException
/*      */   {
/* 1538 */     invokeJaxb(new com.zimbra.soap.admin.message.RenameDistributionListRequest(zimbraId, newName));
/*      */   }
/*      */   
/*      */   public void renameGroup(String zimbraId, String newName)
/*      */     throws ServiceException
/*      */   {
/* 1544 */     invokeJaxb(new com.zimbra.soap.admin.message.RenameDistributionListRequest(zimbraId, newName));
/*      */   }
/*      */   
/*      */   public void setCOS(Account acct, Cos cos) throws ServiceException
/*      */   {
/* 1549 */     HashMap<String, String> attrs = new HashMap();
/* 1550 */     attrs.put("zimbraCOSId", cos.getId());
/* 1551 */     modifyAttrs(acct, attrs);
/*      */   }
/*      */   
/*      */   public Provisioning.SetPasswordResult setPassword(Account acct, String newPassword) throws ServiceException
/*      */   {
/* 1556 */     SetPasswordResponse resp = (SetPasswordResponse)invokeJaxb(new com.zimbra.soap.admin.message.SetPasswordRequest(acct.getId(), newPassword));
/*      */     
/* 1558 */     Provisioning.SetPasswordResult result = new Provisioning.SetPasswordResult();
/* 1559 */     String eMsg = resp.getMessage();
/* 1560 */     if (eMsg != null)
/* 1561 */       result.setMessage(eMsg);
/* 1562 */     return result;
/*      */   }
/*      */   
/*      */   public void checkPasswordStrength(Account acct, String password) throws ServiceException
/*      */   {
/* 1567 */     invokeJaxb(new com.zimbra.soap.admin.message.CheckPasswordStrengthRequest(acct.getId(), password));
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public void modifyAttrs(Entry e, Map<String, ? extends Object> attrs, boolean checkImmutable)
/*      */     throws ServiceException
/*      */   {
/* 1575 */     SoapEntry se = (SoapEntry)e;
/* 1576 */     se.modifyAttrs(this, attrs, checkImmutable);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public void modifyAttrs(Entry e, Map<String, ? extends Object> attrs, boolean checkImmutable, boolean allowCallback)
/*      */     throws ServiceException
/*      */   {
/* 1586 */     modifyAttrs(e, attrs, checkImmutable);
/*      */   }
/*      */   
/*      */   public void reload(Entry e) throws ServiceException
/*      */   {
/* 1591 */     SoapEntry se = (SoapEntry)e;
/* 1592 */     se.reload(this);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   public Set<String> getDistributionLists(Account acct)
/*      */     throws ServiceException
/*      */   {
/* 1601 */     Set<String> dls = (Set)acct.getCachedData("DL_SET");
/* 1602 */     if (dls != null) {
/* 1603 */       return dls;
/*      */     }
/*      */     
/* 1606 */     dls = getDistributionLists(acct, false);
/* 1607 */     acct.setCachedData("DL_SET", dls);
/* 1608 */     return dls;
/*      */   }
/*      */   
/*      */   public Set<String> getDirectDistributionLists(Account acct)
/*      */     throws ServiceException
/*      */   {
/* 1614 */     Set<String> dls = (Set)acct.getCachedData("DIRECT_DL_SET");
/* 1615 */     if (dls != null) {
/* 1616 */       return dls;
/*      */     }
/*      */     
/* 1619 */     dls = getDistributionLists(acct, true);
/* 1620 */     acct.setCachedData("DIRECT_DL_SET", dls);
/* 1621 */     return dls;
/*      */   }
/*      */   
/*      */   private Set<String> getDistributionLists(Account acct, boolean directOnly) throws ServiceException
/*      */   {
/* 1626 */     Set<String> dls = new java.util.HashSet();
/*      */     
/* 1628 */     List<DistributionList> lists = getDistributionLists(acct, directOnly, null);
/*      */     
/* 1630 */     for (DistributionList dl : lists) {
/* 1631 */       dls.add(dl.getId());
/*      */     }
/* 1633 */     dls = java.util.Collections.unmodifiableSet(dls);
/* 1634 */     return dls;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public Set<String> getGroups(Account acct)
/*      */     throws ServiceException
/*      */   {
/* 1642 */     Set<String> groupIds = (Set)acct.getCachedData("GROUP_SET");
/* 1643 */     if (groupIds != null) {
/* 1644 */       return groupIds;
/*      */     }
/*      */     
/* 1647 */     groupIds = new java.util.HashSet();
/*      */     
/* 1649 */     List<Group> groups = getGroups(acct, false, null);
/*      */     
/* 1651 */     for (Group dl : groups) {
/* 1652 */       groupIds.add(dl.getId());
/*      */     }
/* 1654 */     groupIds = java.util.Collections.unmodifiableSet(groupIds);
/* 1655 */     acct.setCachedData("GROUP_SET", groupIds);
/* 1656 */     return groupIds;
/*      */   }
/*      */   
/*      */ 
/*      */   public List<DistributionList> getDistributionLists(Account acct, boolean directOnly, Map<String, String> via)
/*      */     throws ServiceException
/*      */   {
/* 1663 */     ArrayList<DistributionList> result = new ArrayList();
/* 1664 */     GetAccountMembershipResponse resp = (GetAccountMembershipResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetAccountMembershipRequest(getSelector(acct)));
/*      */     
/* 1666 */     for (DLInfo dlInfo : resp.getDlList()) {
/* 1667 */       String viaList = dlInfo.getVia();
/* 1668 */       if ((!directOnly) || (viaList == null)) {
/* 1669 */         DistributionList dl = new SoapDistributionList(dlInfo, this);
/* 1670 */         if ((via != null) && (viaList != null))
/* 1671 */           via.put(dl.getName(), viaList);
/* 1672 */         result.add(dl);
/*      */       } }
/* 1674 */     return result;
/*      */   }
/*      */   
/*      */   public List<Group> getGroups(Account acct, boolean directOnly, Map<String, String> via)
/*      */     throws ServiceException
/*      */   {
/* 1680 */     ArrayList<Group> result = new ArrayList();
/* 1681 */     GetAccountMembershipResponse resp = (GetAccountMembershipResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetAccountMembershipRequest(getSelector(acct)));
/*      */     
/*      */ 
/* 1684 */     for (DLInfo dlInfo : resp.getDlList()) {
/* 1685 */       String viaList = dlInfo.getVia();
/* 1686 */       if ((!directOnly) || (viaList == null))
/*      */       {
/*      */ 
/* 1689 */         Group group = makeGroup(dlInfo);
/* 1690 */         if ((via != null) && (viaList != null)) {
/* 1691 */           via.put(group.getName(), viaList);
/*      */         }
/* 1693 */         result.add(group);
/*      */       } }
/* 1695 */     return result;
/*      */   }
/*      */   
/*      */   public boolean inDistributionList(Account acct, String zimbraId)
/*      */     throws ServiceException
/*      */   {
/* 1701 */     return getDistributionLists(acct).contains(zimbraId);
/*      */   }
/*      */   
/*      */ 
/*      */   public List<DistributionList> getDistributionLists(DistributionList list, boolean directOnly, Map<String, String> via)
/*      */     throws ServiceException
/*      */   {
/* 1708 */     ArrayList<DistributionList> result = new ArrayList();
/* 1709 */     com.zimbra.soap.admin.message.GetDistributionListMembershipRequest req = new com.zimbra.soap.admin.message.GetDistributionListMembershipRequest(getSelector(list), null, null);
/*      */     
/*      */ 
/* 1712 */     GetDistributionListMembershipResponse resp = (GetDistributionListMembershipResponse)invokeJaxb(req);
/* 1713 */     for (com.zimbra.soap.admin.type.DistributionListMembershipInfo dlMemInfo : resp.getDls()) {
/* 1714 */       String viaList = dlMemInfo.getVia();
/* 1715 */       if ((!directOnly) || (viaList == null))
/*      */       {
/* 1717 */         DistributionList dl = new SoapDistributionList(dlMemInfo, this);
/* 1718 */         if ((via != null) && (viaList != null)) {
/* 1719 */           via.put(dl.getName(), viaList);
/*      */         }
/* 1721 */         result.add(dl);
/*      */       } }
/* 1723 */     return result;
/*      */   }
/*      */   
/*      */   private List<AccountInfo> getAllAccountsInfo(Domain d, Server s) throws ServiceException
/*      */   {
/* 1728 */     GetAllAccountsResponse resp = (GetAllAccountsResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetAllAccountsRequest(getSelector(s), getSelector(d)));
/*      */     
/*      */ 
/* 1731 */     return resp.getAccountList();
/*      */   }
/*      */   
/*      */   public List<Account> getAllAccounts(Domain d)
/*      */     throws ServiceException
/*      */   {
/* 1737 */     return getAllAccounts(d, (Server)null);
/*      */   }
/*      */   
/*      */   public List<Account> getAllAccounts(Domain d, Server s) throws ServiceException
/*      */   {
/* 1742 */     ArrayList<Account> result = new ArrayList();
/* 1743 */     for (AccountInfo acct : getAllAccountsInfo(d, s)) {
/* 1744 */       result.add(new SoapAccount(acct, this));
/*      */     }
/* 1746 */     return result;
/*      */   }
/*      */   
/*      */   public void getAllAccounts(Domain d, NamedEntry.Visitor visitor)
/*      */     throws ServiceException
/*      */   {
/* 1752 */     getAllAccounts(d, (Server)null, visitor);
/*      */   }
/*      */   
/*      */   public void getAllAccounts(Domain d, Server s, NamedEntry.Visitor visitor)
/*      */     throws ServiceException
/*      */   {
/* 1758 */     for (AccountInfo acct : getAllAccountsInfo(d, s)) {
/* 1759 */       visitor.visit(new SoapAccount(acct, this));
/*      */     }
/*      */   }
/*      */   
/*      */   private List<CalendarResourceInfo> getAllCalendarResourcesInfo(Domain d, Server s)
/*      */     throws ServiceException
/*      */   {
/* 1766 */     GetAllCalendarResourcesResponse resp = (GetAllCalendarResourcesResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetAllCalendarResourcesRequest(getSelector(s), getSelector(d)));
/*      */     
/*      */ 
/* 1769 */     return resp.getCalendarResourceList();
/*      */   }
/*      */   
/*      */   public List<CalendarResource> getAllCalendarResources(Domain d)
/*      */     throws ServiceException
/*      */   {
/* 1775 */     return getAllCalendarResources(d, (Server)null);
/*      */   }
/*      */   
/*      */   public List<CalendarResource> getAllCalendarResources(Domain d, Server s) throws ServiceException
/*      */   {
/* 1780 */     ArrayList<CalendarResource> result = new ArrayList();
/* 1781 */     for (CalendarResourceInfo rsrc : getAllCalendarResourcesInfo(d, s)) {
/* 1782 */       result.add(new SoapCalendarResource(rsrc, this));
/*      */     }
/* 1784 */     return result;
/*      */   }
/*      */   
/*      */   public void getAllCalendarResources(Domain d, NamedEntry.Visitor visitor)
/*      */     throws ServiceException
/*      */   {
/* 1790 */     getAllCalendarResources(d, (Server)null, visitor);
/*      */   }
/*      */   
/*      */   public void getAllCalendarResources(Domain d, Server s, NamedEntry.Visitor visitor)
/*      */     throws ServiceException
/*      */   {
/* 1796 */     for (CalendarResourceInfo rsrc : getAllCalendarResourcesInfo(d, s)) {
/* 1797 */       visitor.visit(new SoapCalendarResource(rsrc, this));
/*      */     }
/*      */   }
/*      */   
/*      */   public List<DistributionList> getAllDistributionLists(Domain d)
/*      */     throws ServiceException
/*      */   {
/* 1804 */     ArrayList<DistributionList> result = new ArrayList();
/* 1805 */     GetAllDistributionListsResponse resp = (GetAllDistributionListsResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetAllDistributionListsRequest(getSelector(d)));
/*      */     
/* 1807 */     for (DistributionListInfo dl : resp.getDls()) {
/* 1808 */       result.add(new SoapDistributionList(dl, this));
/*      */     }
/* 1810 */     return result;
/*      */   }
/*      */   
/*      */   public List<Group> getAllGroups(Domain domain) throws ServiceException
/*      */   {
/* 1815 */     ArrayList<Group> result = new ArrayList();
/* 1816 */     GetAllDistributionListsResponse resp = (GetAllDistributionListsResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetAllDistributionListsRequest(getSelector(domain)));
/*      */     
/* 1818 */     for (DistributionListInfo dl : resp.getDls()) {
/* 1819 */       result.add(makeGroup(dl));
/*      */     }
/* 1821 */     return result;
/*      */   }
/*      */   
/*      */ 
/*      */   public Provisioning.SearchGalResult autoCompleteGal(Domain d, String query, GalSearchType type, int limit, com.zimbra.cs.account.GalContact.Visitor visitor)
/*      */     throws ServiceException
/*      */   {
/* 1828 */     String typeStr = type == null ? GalSearchType.all.name() : type.name();
/*      */     
/* 1830 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.AUTO_COMPLETE_GAL_REQUEST);
/* 1831 */     req.addElement("name").setText(query);
/* 1832 */     req.addAttribute("domain", d.getName());
/* 1833 */     req.addAttribute("type", typeStr);
/* 1834 */     req.addAttribute("limit", limit);
/*      */     
/* 1836 */     Element resp = invoke(req);
/*      */     
/* 1838 */     Provisioning.SearchGalResult result = Provisioning.SearchGalResult.newSearchGalResult(visitor);
/* 1839 */     result.setHadMore(resp.getAttributeBool("more", false));
/* 1840 */     result.setTokenizeKey(resp.getAttribute("tokenizeKey", null));
/* 1841 */     for (Element e : resp.listElements("cn")) {
/* 1842 */       result.addMatch(new com.zimbra.cs.account.GalContact(e.getAttribute("id"), getAttrs(e)));
/*      */     }
/* 1844 */     return result;
/*      */   }
/*      */   
/*      */   public List<com.zimbra.cs.account.NamedEntry> searchDirectory(SearchDirectoryOptions options) throws ServiceException
/*      */   {
/* 1849 */     List<com.zimbra.cs.account.NamedEntry> result = new ArrayList();
/*      */     
/* 1851 */     SearchDirectoryRequest req = new SearchDirectoryRequest();
/* 1852 */     req.setQuery(options.getFilterString());
/*      */     
/* 1854 */     if (options.getMaxResults() != 0) {
/* 1855 */       req.setMaxResults(Integer.valueOf(options.getMaxResults()));
/*      */     }
/*      */     
/* 1858 */     if (options.getDomain() != null) {
/* 1859 */       req.setDomain(options.getDomain().getName());
/*      */     }
/*      */     
/* 1862 */     if (options.getSortAttr() != null) {
/* 1863 */       req.setSortBy(options.getSortAttr());
/*      */     }
/*      */     
/* 1866 */     Set<com.zimbra.cs.account.SearchDirectoryOptions.ObjectType> types = options.getTypes();
/* 1867 */     if (types != null) {
/* 1868 */       req.setTypes(com.zimbra.cs.account.SearchDirectoryOptions.ObjectType.toCSVString(types));
/*      */     }
/*      */     
/* 1871 */     req.setSortAscending(Boolean.valueOf(options.getSortOpt() != com.zimbra.cs.account.SearchDirectoryOptions.SortOpt.SORT_DESCENDING));
/*      */     
/* 1873 */     if (options.getReturnAttrs() != null) {
/* 1874 */       req.addAttrs(options.getReturnAttrs());
/*      */     }
/*      */     
/*      */ 
/* 1878 */     SearchDirectoryResponse resp = (SearchDirectoryResponse)invokeJaxb(req);
/*      */     
/* 1880 */     List<com.zimbra.soap.admin.type.AdminObjectInterface> entries = resp.getEntries();
/* 1881 */     for (com.zimbra.soap.admin.type.AdminObjectInterface entry : entries) {
/* 1882 */       if ((entry instanceof AccountInfo)) {
/* 1883 */         result.add(new SoapAccount((AccountInfo)entry, this));
/* 1884 */       } else if ((entry instanceof CalendarResourceInfo)) {
/* 1885 */         result.add(new SoapCalendarResource((CalendarResourceInfo)entry, this));
/* 1886 */       } else if ((entry instanceof com.zimbra.soap.admin.type.AliasInfo)) {
/* 1887 */         result.add(new SoapAlias((com.zimbra.soap.admin.type.AliasInfo)entry, this));
/* 1888 */       } else if ((entry instanceof DistributionListInfo)) {
/* 1889 */         result.add(new SoapDistributionList((DistributionListInfo)entry, this));
/* 1890 */       } else if ((entry instanceof DomainInfo)) {
/* 1891 */         result.add(new SoapDomain((DomainInfo)entry, this));
/*      */       }
/*      */     }
/* 1894 */     return result;
/*      */   }
/*      */   
/*      */   public Provisioning.SearchGalResult searchGal(Domain d, String query, GalSearchType type, String token, int limit, int offset, String sortBy)
/*      */     throws ServiceException
/*      */   {
/* 1900 */     String typeStr = type == null ? GalSearchType.all.name() : type.name();
/*      */     
/* 1902 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.SEARCH_GAL_REQUEST);
/* 1903 */     req.addElement("name").setText(query);
/* 1904 */     req.addAttribute("domain", d.getName());
/* 1905 */     req.addAttribute("type", typeStr);
/* 1906 */     if (limit > 0)
/* 1907 */       req.addAttribute("limit", limit);
/* 1908 */     if (offset > 0)
/* 1909 */       req.addAttribute("offset", limit);
/* 1910 */     if (sortBy != null) {
/* 1911 */       req.addAttribute("sortBy", sortBy);
/*      */     }
/* 1913 */     if (token != null) { req.addAttribute("token", token);
/*      */     }
/* 1915 */     Element resp = invoke(req);
/*      */     
/* 1917 */     Provisioning.SearchGalResult result = Provisioning.SearchGalResult.newSearchGalResult(null);
/* 1918 */     result.setToken(resp.getAttribute("token", null));
/* 1919 */     result.setHadMore(resp.getAttributeBool("more", false));
/* 1920 */     result.setTokenizeKey(resp.getAttribute("tokenizeKey", null));
/* 1921 */     for (Element e : resp.listElements("cn")) {
/* 1922 */       result.addMatch(new com.zimbra.cs.account.GalContact(e.getAttribute("id"), getAttrs(e)));
/*      */     }
/* 1924 */     return result;
/*      */   }
/*      */   
/*      */   public void addMembers(DistributionList list, String[] members)
/*      */     throws ServiceException
/*      */   {
/* 1930 */     invokeJaxb(new com.zimbra.soap.admin.message.AddDistributionListMemberRequest(list.getId(), Arrays.asList(members)));
/*      */     
/* 1932 */     reload(list);
/*      */   }
/*      */   
/*      */   public void addGroupMembers(Group group, String[] members)
/*      */     throws ServiceException
/*      */   {
/* 1938 */     invokeJaxb(new com.zimbra.soap.admin.message.AddDistributionListMemberRequest(group.getId(), Arrays.asList(members)));
/*      */     
/* 1940 */     reload(group);
/*      */   }
/*      */   
/*      */   public void removeMembers(DistributionList list, String[] members) throws ServiceException
/*      */   {
/* 1945 */     invokeJaxb(new com.zimbra.soap.admin.message.RemoveDistributionListMemberRequest(list.getId(), Arrays.asList(members)));
/*      */     
/* 1947 */     reload(list);
/*      */   }
/*      */   
/*      */   public void removeGroupMembers(Group group, String[] members) throws ServiceException
/*      */   {
/* 1952 */     invokeJaxb(new com.zimbra.soap.admin.message.RemoveDistributionListMemberRequest(group.getId(), Arrays.asList(members)));
/*      */     
/* 1954 */     reload(group);
/*      */   }
/*      */   
/*      */   static void addAttrElementsMailService(Element req, Map<String, ? extends Object> attrs) throws ServiceException {
/* 1958 */     if (attrs == null) { return;
/*      */     }
/* 1960 */     for (Map.Entry<String, ? extends Object> entry : attrs.entrySet()) {
/* 1961 */       String key = (String)entry.getKey();
/* 1962 */       Object value = entry.getValue();
/* 1963 */       if ((value instanceof String)) {
/* 1964 */         Element a = req.addElement("a");
/* 1965 */         a.addAttribute("name", key);
/* 1966 */         a.setText((String)value);
/* 1967 */       } else if ((value instanceof String[])) {
/* 1968 */         String[] values = (String[])value;
/* 1969 */         for (String v : values) {
/* 1970 */           Element a = req.addElement("a");
/* 1971 */           a.addAttribute("name", key);
/* 1972 */           a.setText(v);
/*      */         }
/*      */       } else {
/* 1975 */         throw ZClientException.CLIENT_ERROR("invalid attr type: " + key + " " + value.getClass().getName(), null);
/*      */       }
/*      */     }
/*      */   }
/*      */   
/*      */ 
/*      */   public com.zimbra.cs.account.Identity createIdentity(Account account, String identityName, Map<String, Object> attrs)
/*      */     throws ServiceException
/*      */   {
/* 1984 */     com.zimbra.soap.account.type.Identity id = new com.zimbra.soap.account.type.Identity(identityName, null);
/*      */     
/* 1986 */     id.setAttrs(attrs);
/* 1987 */     com.zimbra.soap.account.message.CreateIdentityRequest request = new com.zimbra.soap.account.message.CreateIdentityRequest(id);
/* 1988 */     CreateIdentityResponse response = (CreateIdentityResponse)invokeJaxbOnTargetAccount(request, account.getId());
/*      */     
/* 1990 */     return new SoapIdentity(account, response.getIdentity(), this);
/*      */   }
/*      */   
/*      */ 
/*      */   public com.zimbra.cs.account.Identity restoreIdentity(Account account, String identityName, Map<String, Object> attrs)
/*      */     throws ServiceException
/*      */   {
/* 1997 */     throw new UnsupportedOperationException();
/*      */   }
/*      */   
/*      */   public void deleteIdentity(Account account, String identityName)
/*      */     throws ServiceException
/*      */   {
/* 2003 */     com.zimbra.soap.account.type.NameId identity = new com.zimbra.soap.account.type.NameId(identityName, null);
/* 2004 */     com.zimbra.soap.account.message.DeleteIdentityRequest request = new com.zimbra.soap.account.message.DeleteIdentityRequest(identity);
/* 2005 */     invokeJaxbOnTargetAccount(request, account.getId());
/*      */   }
/*      */   
/*      */   public List<com.zimbra.cs.account.Identity> getAllIdentities(Account account)
/*      */     throws ServiceException
/*      */   {
/* 2011 */     List<com.zimbra.cs.account.Identity> result = new ArrayList();
/* 2012 */     GetIdentitiesResponse response = (GetIdentitiesResponse)invokeJaxbOnTargetAccount(new com.zimbra.soap.account.message.GetIdentitiesRequest(), account.getId());
/*      */     
/*      */ 
/*      */ 
/* 2016 */     for (com.zimbra.soap.account.type.Identity identity : response.getIdentities()) {
/* 2017 */       result.add(new SoapIdentity(account, identity, this));
/*      */     }
/* 2019 */     return result;
/*      */   }
/*      */   
/*      */ 
/*      */   public void modifyIdentity(Account account, String identityName, Map<String, Object> attrs)
/*      */     throws ServiceException
/*      */   {
/* 2026 */     com.zimbra.soap.account.type.Identity id = new com.zimbra.soap.account.type.Identity(identityName, null);
/*      */     
/* 2028 */     id.setAttrs(attrs);
/* 2029 */     com.zimbra.soap.account.message.ModifyIdentityRequest request = new com.zimbra.soap.account.message.ModifyIdentityRequest(id);
/* 2030 */     invokeJaxbOnTargetAccount(request, account.getId());
/*      */   }
/*      */   
/*      */   public Signature createSignature(Account account, String signatureName, Map<String, Object> attrs) throws ServiceException
/*      */   {
/* 2035 */     if (attrs.get("zimbraSignatureName") != null) {
/* 2036 */       throw ZClientException.CLIENT_ERROR("invalid attr: zimbraSignatureName", null);
/*      */     }
/* 2038 */     Element.XMLElement req = new Element.XMLElement(AccountConstants.CREATE_SIGNATURE_REQUEST);
/* 2039 */     Element signature = req.addElement("signature");
/* 2040 */     signature.addAttribute("name", signatureName);
/* 2041 */     SoapSignature.toXML(signature, attrs);
/* 2042 */     Element response = invokeOnTargetAccount(req, account.getId()).getElement("signature");
/* 2043 */     return new SoapSignature(account, response, this);
/*      */   }
/*      */   
/*      */   public Signature restoreSignature(Account account, String signatureName, Map<String, Object> attrs) throws ServiceException
/*      */   {
/* 2048 */     throw new UnsupportedOperationException();
/*      */   }
/*      */   
/*      */   public void modifySignature(Account account, String signatureId, Map<String, Object> attrs) throws ServiceException
/*      */   {
/* 2053 */     if (attrs.get("zimbraSignatureId") != null) {
/* 2054 */       throw ZClientException.CLIENT_ERROR("invalid attr: zimbraSignatureId", null);
/*      */     }
/* 2056 */     Element.XMLElement req = new Element.XMLElement(AccountConstants.MODIFY_SIGNATURE_REQUEST);
/* 2057 */     Element signature = req.addElement("signature");
/* 2058 */     signature.addAttribute("id", signatureId);
/* 2059 */     SoapSignature.toXML(signature, attrs);
/* 2060 */     invokeOnTargetAccount(req, account.getId());
/*      */   }
/*      */   
/*      */   public void deleteSignature(Account account, String signatureId) throws ServiceException
/*      */   {
/* 2065 */     Element.XMLElement req = new Element.XMLElement(AccountConstants.DELETE_SIGNATURE_REQUEST);
/* 2066 */     Element signature = req.addElement("signature");
/* 2067 */     signature.addAttribute("id", signatureId);
/* 2068 */     invokeOnTargetAccount(req, account.getId());
/*      */   }
/*      */   
/*      */   public List<Signature> getAllSignatures(Account account) throws ServiceException
/*      */   {
/* 2073 */     List<Signature> result = new ArrayList();
/* 2074 */     Element.XMLElement req = new Element.XMLElement(AccountConstants.GET_SIGNATURES_REQUEST);
/* 2075 */     Element resp = invokeOnTargetAccount(req, account.getId());
/* 2076 */     for (Element signature : resp.listElements("signature")) {
/* 2077 */       result.add(new SoapSignature(account, signature, this));
/*      */     }
/* 2079 */     return result;
/*      */   }
/*      */   
/*      */   public DataSource createDataSource(Account account, DataSourceType dsType, String dsName, Map<String, Object> attrs) throws ServiceException
/*      */   {
/* 2084 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.CREATE_DATA_SOURCE_REQUEST);
/* 2085 */     req.addElement("id").setText(account.getId());
/* 2086 */     Element ds = req.addElement("dataSource");
/* 2087 */     ds.addAttribute("name", dsName);
/* 2088 */     ds.addAttribute("type", dsType.name());
/* 2089 */     addAttrElements(ds, attrs);
/* 2090 */     Element response = invoke(req).getElement("dataSource");
/* 2091 */     return new SoapDataSource(account, response, this);
/*      */   }
/*      */   
/*      */   public DataSource createDataSource(Account account, DataSourceType dsType, String dsName, Map<String, Object> attrs, boolean passwdAlreadyEncrypted) throws ServiceException
/*      */   {
/* 2096 */     throw new UnsupportedOperationException();
/*      */   }
/*      */   
/*      */   public DataSource restoreDataSource(Account account, DataSourceType dsType, String dsName, Map<String, Object> attrs) throws ServiceException
/*      */   {
/* 2101 */     throw new UnsupportedOperationException();
/*      */   }
/*      */   
/*      */   public void deleteDataSource(Account account, String dataSourceId) throws ServiceException
/*      */   {
/* 2106 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.DELETE_DATA_SOURCE_REQUEST);
/* 2107 */     req.addElement("id").setText(account.getId());
/* 2108 */     Element ds = req.addElement("dataSource");
/* 2109 */     ds.addAttribute("id", dataSourceId);
/* 2110 */     invoke(req);
/*      */   }
/*      */   
/*      */   public List<DataSource> getAllDataSources(Account account) throws ServiceException
/*      */   {
/* 2115 */     List<DataSource> result = new ArrayList();
/* 2116 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.GET_DATA_SOURCES_REQUEST);
/* 2117 */     req.addElement("id").setText(account.getId());
/* 2118 */     Element resp = invoke(req);
/* 2119 */     for (Element dataSource : resp.listElements("dataSource")) {
/* 2120 */       result.add(new SoapDataSource(account, dataSource, this));
/*      */     }
/* 2122 */     return result;
/*      */   }
/*      */   
/*      */   public void modifyDataSource(Account account, String dataSourceId, Map<String, Object> attrs) throws ServiceException
/*      */   {
/* 2127 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.MODIFY_DATA_SOURCE_REQUEST);
/* 2128 */     req.addElement("id").setText(account.getId());
/* 2129 */     Element ds = req.addElement("dataSource");
/* 2130 */     ds.addAttribute("id", dataSourceId);
/* 2131 */     addAttrElements(ds, attrs);
/* 2132 */     invoke(req);
/*      */   }
/*      */   
/*      */   public DataSource get(Account account, com.zimbra.common.account.Key.DataSourceBy keyType, String key)
/*      */     throws ServiceException
/*      */   {
/* 2138 */     switch (keyType) {
/*      */     case name: 
/* 2140 */       for (DataSource source : getAllDataSources(account))
/* 2141 */         if (source.getName().equalsIgnoreCase(key))
/* 2142 */           return source;
/* 2143 */       return null;
/*      */     case id: 
/* 2145 */       for (DataSource source : getAllDataSources(account))
/* 2146 */         if (source.getId().equalsIgnoreCase(key))
/* 2147 */           return source;
/* 2148 */       return null;
/*      */     }
/* 2150 */     return null;
/*      */   }
/*      */   
/*      */   public List<XMPPComponent> getAllXMPPComponents()
/*      */     throws ServiceException
/*      */   {
/* 2156 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.GET_ALL_XMPPCOMPONENTS_REQUEST);
/* 2157 */     Element response = invoke(req);
/*      */     
/* 2159 */     List<XMPPComponent> toRet = new ArrayList();
/* 2160 */     for (Element e : response.listElements("xmppcomponent")) {
/* 2161 */       toRet.add(new SoapXMPPComponent(e, this));
/*      */     }
/* 2163 */     return toRet;
/*      */   }
/*      */   
/*      */   public XMPPComponent createXMPPComponent(String name, Domain domain, Server server, Map<String, Object> attrs) throws ServiceException
/*      */   {
/* 2168 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.CREATE_XMPPCOMPONENT_REQUEST);
/*      */     
/* 2170 */     Element c = req.addElement("xmppcomponent");
/* 2171 */     c.addAttribute("name", name);
/*      */     
/* 2173 */     Element domainElt = c.addElement("domain");
/* 2174 */     domainElt.addAttribute("by", "id");
/* 2175 */     domainElt.setText(domain.getId());
/*      */     
/* 2177 */     Element serverElt = c.addElement("server");
/* 2178 */     serverElt.addAttribute("by", "id");
/* 2179 */     serverElt.setText(server.getId());
/*      */     
/* 2181 */     addAttrElements(c, attrs);
/* 2182 */     Element response = invoke(req);
/* 2183 */     response = response.getElement("xmppcomponent");
/* 2184 */     return new SoapXMPPComponent(response, this);
/*      */   }
/*      */   
/*      */   public XMPPComponent get(Key.XMPPComponentBy keyType, String key) throws ServiceException
/*      */   {
/* 2189 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.GET_XMPPCOMPONENT_REQUEST);
/*      */     
/* 2191 */     Element c = req.addElement("xmppcomponent");
/* 2192 */     c.addAttribute("by", keyType.name());
/* 2193 */     c.setText(key);
/* 2194 */     Element response = invoke(req);
/* 2195 */     response = response.getElement("xmppcomponent");
/* 2196 */     return new SoapXMPPComponent(response, this);
/*      */   }
/*      */   
/*      */   public void deleteXMPPComponent(XMPPComponent comp) throws ServiceException
/*      */   {
/* 2201 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.DELETE_XMPPCOMPONENT_REQUEST);
/*      */     
/* 2203 */     Element c = req.addElement("xmppcomponent");
/* 2204 */     c.addAttribute("by", "id");
/* 2205 */     c.setText(comp.getId());
/* 2206 */     invoke(req);
/*      */   }
/*      */   
/*      */   public com.zimbra.cs.account.Identity get(Account account, com.zimbra.common.account.Key.IdentityBy keyType, String key)
/*      */     throws ServiceException
/*      */   {
/* 2212 */     switch (keyType) {
/*      */     case name: 
/* 2214 */       for (com.zimbra.cs.account.Identity identity : getAllIdentities(account))
/* 2215 */         if (identity.getName().equalsIgnoreCase(key))
/* 2216 */           return identity;
/* 2217 */       return null;
/*      */     case id: 
/* 2219 */       for (com.zimbra.cs.account.Identity identity : getAllIdentities(account))
/* 2220 */         if (identity.getId().equalsIgnoreCase(key))
/* 2221 */           return identity;
/* 2222 */       return null;
/*      */     }
/* 2224 */     return null;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public Signature get(Account account, com.zimbra.common.account.Key.SignatureBy keyType, String key)
/*      */     throws ServiceException
/*      */   {
/* 2232 */     switch (keyType) {
/*      */     case name: 
/* 2234 */       for (Signature signature : getAllSignatures(account))
/* 2235 */         if (signature.getName().equalsIgnoreCase(key))
/* 2236 */           return signature;
/* 2237 */       return null;
/*      */     case id: 
/* 2239 */       for (Signature signature : getAllSignatures(account))
/* 2240 */         if (signature.getId().equalsIgnoreCase(key))
/* 2241 */           return signature;
/* 2242 */       return null;
/*      */     }
/* 2244 */     return null;
/*      */   }
/*      */   
/*      */   public void deleteMailbox(String accountId)
/*      */     throws ServiceException
/*      */   {
/* 2250 */     invokeJaxb(new com.zimbra.soap.admin.message.DeleteMailboxRequest(accountId));
/*      */   }
/*      */   
/*      */   public MailboxWithMailboxId purgeMessages(Account account) throws ServiceException {
/* 2254 */     Server server = account.getServer();
/* 2255 */     String serviceHost = server.getAttr("zimbraServiceHostname");
/* 2256 */     PurgeMessagesResponse resp = (PurgeMessagesResponse)invokeJaxb(new com.zimbra.soap.admin.message.PurgeMessagesRequest(account.getId()), serviceHost);
/* 2257 */     if (resp.getMailboxes().isEmpty()) {
/* 2258 */       return null;
/*      */     }
/* 2260 */     return (MailboxWithMailboxId)resp.getMailboxes().get(0);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   private Element toXML(Element req, String targetType, TargetBy targetBy, String target)
/*      */   {
/* 2271 */     Element eTarget = req.addElement("target");
/* 2272 */     eTarget.addAttribute("type", targetType);
/* 2273 */     if (target != null) {
/* 2274 */       eTarget.addAttribute("by", targetBy.toString());
/* 2275 */       eTarget.setText(target);
/*      */     }
/*      */     
/* 2278 */     return eTarget;
/*      */   }
/*      */   
/*      */ 
/*      */   private Element toXML(Element req, String granteeType, GranteeSelector.GranteeBy granteeBy, String grantee)
/*      */   {
/* 2284 */     return toXML(req, granteeType, granteeBy, grantee, null);
/*      */   }
/*      */   
/*      */   private Element toXML(Element req, String granteeType, GranteeSelector.GranteeBy granteeBy, String grantee, String secret)
/*      */   {
/* 2289 */     Element eGrantee = req.addElement("grantee");
/* 2290 */     if (granteeType != null) {
/* 2291 */       eGrantee.addAttribute("type", granteeType);
/*      */     }
/* 2293 */     if (granteeBy != null) {
/* 2294 */       eGrantee.addAttribute("by", granteeBy.toString());
/*      */     }
/* 2296 */     if (secret != null) {
/* 2297 */       eGrantee.addAttribute("secret", secret);
/*      */     }
/* 2299 */     if (grantee != null) {
/* 2300 */       eGrantee.setText(grantee);
/*      */     }
/* 2302 */     return eGrantee;
/*      */   }
/*      */   
/*      */ 
/*      */   private Element toXML(Element req, String right, RightModifier rightModifier)
/*      */   {
/* 2308 */     Element eRight = req.addElement("right");
/* 2309 */     if (rightModifier != null) {
/* 2310 */       eRight.addAttribute(rightModifier.getSoapAttrMapping(), true);
/*      */     }
/* 2312 */     eRight.setText(right);
/*      */     
/* 2314 */     return eRight;
/*      */   }
/*      */   
/*      */   public Map<String, List<Provisioning.RightsDoc>> getRightsDoc(String[] pkgs)
/*      */     throws ServiceException
/*      */   {
/* 2320 */     GetRightsDocRequest req = new GetRightsDocRequest();
/* 2321 */     if (pkgs != null) {
/* 2322 */       for (String pkg : pkgs)
/* 2323 */         req.addPkg(new com.zimbra.soap.admin.type.PackageSelector(pkg));
/*      */     }
/* 2325 */     GetRightsDocResponse resp = (GetRightsDocResponse)invokeJaxb(req);
/*      */     
/* 2327 */     Map<String, List<Provisioning.RightsDoc>> allDocs = new java.util.TreeMap();
/*      */     
/* 2329 */     for (PackageRightsInfo ePkg : resp.getPackages()) {
/* 2330 */       docs = com.google.common.collect.Lists.newArrayList();
/* 2331 */       allDocs.put(ePkg.getName(), docs);
/* 2332 */       for (com.zimbra.soap.admin.type.CmdRightsInfo eCmd : ePkg.getCmds())
/* 2333 */         docs.add(new Provisioning.RightsDoc(eCmd)); }
/*      */     List<Provisioning.RightsDoc> docs;
/* 2335 */     return allDocs;
/*      */   }
/*      */   
/*      */   public Right getRight(String rightName, boolean expandAllAttrs)
/*      */     throws ServiceException
/*      */   {
/* 2341 */     GetRightResponse resp = (GetRightResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetRightRequest(rightName, Boolean.valueOf(expandAllAttrs)));
/*      */     
/*      */ 
/*      */ 
/* 2345 */     return com.zimbra.cs.account.accesscontrol.RightCommand.RightNameToRight(resp.getRight().getName());
/*      */   }
/*      */   
/*      */ 
/*      */   public List<Right> getAllRights(String targetType, boolean expandAllAttrs, String rightClass)
/*      */     throws ServiceException
/*      */   {
/* 2352 */     GetAllRightsResponse resp = (GetAllRightsResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetAllRightsRequest(targetType, Boolean.valueOf(expandAllAttrs), rightClass));
/*      */     
/* 2354 */     List<Right> rights = new ArrayList();
/* 2355 */     for (RightInfo rInfo : resp.getRights())
/*      */     {
/*      */ 
/* 2358 */       rights.add(com.zimbra.cs.account.accesscontrol.RightCommand.RightNameToRight(rInfo.getName()));
/*      */     }
/* 2360 */     return rights;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public boolean checkRight(String targetType, TargetBy targetBy, String target, GranteeSelector.GranteeBy granteeBy, String grantee, String right, Map<String, Object> attrs, AccessManager.ViaGrant via)
/*      */     throws ServiceException
/*      */   {
/* 2368 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.CHECK_RIGHT_REQUEST);
/* 2369 */     toXML(req, targetType, targetBy, target);
/* 2370 */     toXML(req, null, granteeBy, grantee);
/* 2371 */     toXML(req, right, null);
/*      */     
/* 2373 */     addAttrElements(req, attrs);
/*      */     
/* 2375 */     Element resp = invoke(req);
/* 2376 */     boolean result = resp.getAttributeBool("allow");
/* 2377 */     if (via != null) {
/* 2378 */       Element eVia = resp.getOptionalElement("via");
/* 2379 */       if (eVia != null) {
/* 2380 */         Element eTarget = eVia.getElement("target");
/* 2381 */         Element eGrantee = eVia.getElement("grantee");
/* 2382 */         Element eRight = eVia.getElement("right");
/* 2383 */         via.setImpl(new com.zimbra.cs.account.accesscontrol.ViaGrantImpl(eTarget.getAttribute("type"), eTarget.getText(), eGrantee.getAttribute("type"), eGrantee.getText(), eRight.getText(), eRight.getAttributeBool("deny", false)));
/*      */       }
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/* 2391 */     return result;
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public com.zimbra.cs.account.accesscontrol.RightCommand.AllEffectiveRights getAllEffectiveRights(String granteeType, GranteeSelector.GranteeBy granteeBy, String grantee, boolean expandSetAttrs, boolean expandGetAttrs)
/*      */     throws ServiceException
/*      */   {
/* 2399 */     GranteeSelector granteeSel = null;
/* 2400 */     if ((granteeType != null) && (granteeBy != null) && (grantee != null)) {
/* 2401 */       granteeSel = new GranteeSelector(com.zimbra.soap.type.GranteeType.fromString(granteeType), granteeBy, grantee);
/*      */     }
/* 2403 */     com.zimbra.soap.admin.message.GetAllEffectiveRightsResponse resp = (com.zimbra.soap.admin.message.GetAllEffectiveRightsResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetAllEffectiveRightsRequest(granteeSel, Boolean.valueOf(expandSetAttrs), Boolean.valueOf(expandGetAttrs)));
/*      */     
/* 2405 */     return com.zimbra.cs.account.accesscontrol.RightCommand.AllEffectiveRights.fromJaxb(resp);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   public RightCommand.EffectiveRights getEffectiveRights(String targetType, TargetBy targetBy, String target, GranteeSelector.GranteeBy granteeBy, String grantee, boolean expandSetAttrs, boolean expandGetAttrs)
/*      */     throws ServiceException
/*      */   {
/* 2414 */     GranteeSelector granteeSel = null;
/* 2415 */     if ((granteeBy != null) && (grantee != null)) {
/* 2416 */       granteeSel = new GranteeSelector(granteeBy, grantee);
/*      */     }
/* 2418 */     com.zimbra.soap.admin.type.EffectiveRightsTargetSelector targetSel = new com.zimbra.soap.admin.type.EffectiveRightsTargetSelector(com.zimbra.soap.type.TargetType.fromString(targetType), targetBy, target);
/*      */     
/*      */ 
/* 2421 */     GetEffectiveRightsResponse resp = (GetEffectiveRightsResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetEffectiveRightsRequest(targetSel, granteeSel, Boolean.valueOf(expandSetAttrs), Boolean.valueOf(expandGetAttrs)));
/*      */     
/*      */ 
/* 2424 */     return RightCommand.EffectiveRights.fromJaxb_EffectiveRights(resp);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */   public RightCommand.EffectiveRights getCreateObjectAttrs(String targetType, Key.DomainBy domainBy, String domain, Key.CosBy cosBy, String cos, GranteeSelector.GranteeBy granteeBy, String grantee)
/*      */     throws ServiceException
/*      */   {
/* 2433 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.GET_CREATE_OBJECT_ATTRS_REQUEST);
/*      */     
/* 2435 */     Element eTarget = req.addElement("target");
/* 2436 */     eTarget.addAttribute("type", targetType);
/*      */     
/* 2438 */     if ((domainBy != null) && (domain != null)) {
/* 2439 */       Element eDomain = req.addElement("domain");
/* 2440 */       eDomain.addAttribute("by", domainBy.toString());
/* 2441 */       eDomain.setText(domain);
/*      */     }
/*      */     
/* 2444 */     if ((cosBy != null) && (cos != null)) {
/* 2445 */       Element eCos = req.addElement("cos");
/* 2446 */       eCos.addAttribute("by", cosBy.toString());
/* 2447 */       eCos.setText(cos);
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/* 2455 */     Element resp = invoke(req);
/* 2456 */     return RightCommand.EffectiveRights.fromXML_CreateObjectAttrs(resp);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public com.zimbra.cs.account.accesscontrol.RightCommand.Grants getGrants(String targetType, TargetBy targetBy, String target, String granteeType, GranteeSelector.GranteeBy granteeBy, String grantee, boolean granteeIncludeGroupsGranteeBelongs)
/*      */     throws ServiceException
/*      */   {
/* 2464 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.GET_GRANTS_REQUEST);
/*      */     
/* 2466 */     if (targetType != null) {
/* 2467 */       toXML(req, targetType, targetBy, target);
/*      */     }
/* 2469 */     if (granteeType != null) {
/* 2470 */       Element eGrantee = toXML(req, granteeType, granteeBy, grantee);
/* 2471 */       eGrantee.addAttribute("all", granteeIncludeGroupsGranteeBelongs);
/*      */     }
/*      */     
/* 2474 */     Element resp = invoke(req);
/* 2475 */     return new com.zimbra.cs.account.accesscontrol.RightCommand.Grants(resp);
/*      */   }
/*      */   
/*      */ 
/*      */   public void grantRight(String targetType, TargetBy targetBy, String target, String granteeType, GranteeSelector.GranteeBy granteeBy, String grantee, String secret, String right, RightModifier rightModifier)
/*      */     throws ServiceException
/*      */   {
/* 2482 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.GRANT_RIGHT_REQUEST);
/* 2483 */     toXML(req, targetType, targetBy, target);
/* 2484 */     toXML(req, granteeType, granteeBy, grantee, secret);
/* 2485 */     toXML(req, right, rightModifier);
/*      */     
/* 2487 */     invoke(req);
/*      */   }
/*      */   
/*      */ 
/*      */   public void revokeRight(String targetType, TargetBy targetBy, String target, String granteeType, GranteeSelector.GranteeBy granteeBy, String grantee, String right, RightModifier rightModifier)
/*      */     throws ServiceException
/*      */   {
/* 2494 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.REVOKE_RIGHT_REQUEST);
/* 2495 */     toXML(req, targetType, targetBy, target);
/* 2496 */     toXML(req, granteeType, granteeBy, grantee);
/* 2497 */     toXML(req, right, rightModifier);
/*      */     
/* 2499 */     invoke(req);
/*      */   }
/*      */   
/*      */   public void flushCache(CacheEntryType type, Provisioning.CacheEntry[] entries) throws ServiceException
/*      */   {
/* 2504 */     flushCache(type.name(), entries, false);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */   public void flushCache(String type, Provisioning.CacheEntry[] entries, boolean allServers)
/*      */     throws ServiceException
/*      */   {
/* 2512 */     CacheSelector sel = new CacheSelector(Boolean.valueOf(allServers), type);
/*      */     
/* 2514 */     if (entries != null) {
/* 2515 */       for (Provisioning.CacheEntry entry : entries) {
/* 2516 */         sel.addEntry(new com.zimbra.soap.admin.type.CacheEntrySelector(toJaxb(entry.mEntryBy), entry.mEntryIdentity));
/*      */       }
/*      */     }
/*      */     
/*      */ 
/* 2521 */     invokeJaxb(new com.zimbra.soap.admin.message.FlushCacheRequest(sel));
/*      */   }
/*      */   
/*      */   public Provisioning.CountAccountResult countAccount(Domain domain) throws ServiceException
/*      */   {
/* 2526 */     CountAccountResponse resp = (CountAccountResponse)invokeJaxb(new com.zimbra.soap.admin.message.CountAccountRequest(getSelector(domain)));
/*      */     
/* 2528 */     Provisioning.CountAccountResult result = new Provisioning.CountAccountResult();
/* 2529 */     for (CosCountInfo cosInfo : resp.getCos()) {
/* 2530 */       result.addCountAccountByCosResult(cosInfo.getId(), cosInfo.getName(), cosInfo.getValue());
/*      */     }
/*      */     
/* 2533 */     return result;
/*      */   }
/*      */   
/*      */   public long countObjects(com.zimbra.soap.admin.type.CountObjectsType type, Domain domain, UCService ucService)
/*      */     throws ServiceException
/*      */   {
/* 2539 */     CountObjectsResponse resp = (CountObjectsResponse)invokeJaxb(new com.zimbra.soap.admin.message.CountObjectsRequest(type, getSelector(domain), getSelector(ucService)));
/*      */     
/* 2541 */     return resp.getNum();
/*      */   }
/*      */   
/*      */   public void purgeAccountCalendarCache(String accountId) throws ServiceException
/*      */   {
/* 2546 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.PURGE_ACCOUNT_CALENDAR_CACHE_REQUEST);
/* 2547 */     req.addAttribute("id", accountId);
/* 2548 */     invoke(req);
/*      */   }
/*      */   
/*      */   public void reloadMemcachedClientConfig() throws ServiceException
/*      */   {
/* 2553 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.RELOAD_MEMCACHED_CLIENT_CONFIG_REQUEST);
/* 2554 */     invoke(req);
/*      */   }
/*      */   
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/*      */   public MemcachedClientConfig getMemcachedClientConfig()
/*      */     throws ServiceException
/*      */   {
/* 2566 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.GET_MEMCACHED_CLIENT_CONFIG_REQUEST);
/* 2567 */     Element resp = invoke(req);
/* 2568 */     MemcachedClientConfig config = new MemcachedClientConfig();
/* 2569 */     config.serverList = resp.getAttribute("serverList", null);
/* 2570 */     config.hashAlgorithm = resp.getAttribute("hashAlgorithm", null);
/* 2571 */     config.binaryProtocol = resp.getAttributeBool("binaryProtocol", false);
/* 2572 */     config.defaultExpirySeconds = ((int)resp.getAttributeLong("defaultExpirySeconds", 0L));
/* 2573 */     config.defaultTimeoutMillis = resp.getAttributeLong("defaultTimeoutMillis", 0L);
/* 2574 */     return config;
/*      */   }
/*      */   
/*      */   public void getShareInfo(Account ownerAcct, Provisioning.PublishedShareInfoVisitor visitor)
/*      */     throws ServiceException
/*      */   {
/* 2580 */     GetShareInfoResponse rsp = (GetShareInfoResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetShareInfoRequest(getSelector(ownerAcct)));
/* 2581 */     for (com.zimbra.soap.type.ShareInfo sInfo : rsp.getShares()) {
/* 2582 */       com.zimbra.cs.account.ShareInfoData sid = com.zimbra.cs.account.ShareInfoData.fromJaxbShareInfo(sInfo);
/* 2583 */       visitor.visit(sid);
/*      */     }
/*      */   }
/*      */   
/*      */   public Map<String, Map<String, Object>> getDomainSMIMEConfig(Domain domain, String configName)
/*      */     throws ServiceException
/*      */   {
/* 2590 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.GET_SMIME_CONFIG_REQUEST);
/*      */     
/* 2592 */     Element eDomain = req.addElement("domain");
/* 2593 */     eDomain.addAttribute("by", "id").setText(domain.getId());
/*      */     
/* 2595 */     if (configName != null) {
/* 2596 */       Element eConfig = req.addElement("config");
/* 2597 */       eConfig.addAttribute("name", configName);
/*      */     }
/*      */     
/* 2600 */     Element resp = invoke(req);
/* 2601 */     Map<String, Map<String, Object>> result = new HashMap();
/* 2602 */     for (Element eConfig : resp.listElements("config")) {
/* 2603 */       result.put(eConfig.getAttribute("name"), getAttrs(eConfig));
/*      */     }
/*      */     
/* 2606 */     return result;
/*      */   }
/*      */   
/*      */   public void modifyDomainSMIMEConfig(Domain domain, String configName, Map<String, Object> attrs) throws ServiceException
/*      */   {
/* 2611 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.MODIFY_SMIME_CONFIG_REQUEST);
/*      */     
/* 2613 */     Element eDomain = req.addElement("domain");
/* 2614 */     eDomain.addAttribute("by", "id").setText(domain.getId());
/*      */     
/* 2616 */     Element eConfig = req.addElement("config");
/* 2617 */     eConfig.addAttribute("name", configName);
/* 2618 */     eConfig.addAttribute("op", "modify");
/*      */     
/* 2620 */     addAttrElements(eConfig, attrs);
/*      */     
/* 2622 */     invoke(req);
/*      */   }
/*      */   
/*      */   public void removeDomainSMIMEConfig(Domain domain, String configName) throws ServiceException
/*      */   {
/* 2627 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.MODIFY_SMIME_CONFIG_REQUEST);
/*      */     
/* 2629 */     Element eDomain = req.addElement("domain");
/* 2630 */     eDomain.addAttribute("by", "id").setText(domain.getId());
/*      */     
/* 2632 */     Element eConfig = req.addElement("config");
/* 2633 */     eConfig.addAttribute("name", configName);
/* 2634 */     eConfig.addAttribute("op", "remove");
/*      */     
/* 2636 */     invoke(req);
/*      */   }
/*      */   
/*      */   public Map<String, Map<String, Object>> getConfigSMIMEConfig(String configName) throws ServiceException
/*      */   {
/* 2641 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.GET_SMIME_CONFIG_REQUEST);
/*      */     
/* 2643 */     if (configName != null) {
/* 2644 */       Element eConfig = req.addElement("config");
/* 2645 */       eConfig.addAttribute("name", configName);
/*      */     }
/*      */     
/* 2648 */     Element resp = invoke(req);
/* 2649 */     Map<String, Map<String, Object>> result = new HashMap();
/* 2650 */     for (Element eConfig : resp.listElements("config")) {
/* 2651 */       result.put(eConfig.getAttribute("name"), getAttrs(eConfig));
/*      */     }
/*      */     
/* 2654 */     return result;
/*      */   }
/*      */   
/*      */   public void modifyConfigSMIMEConfig(String configName, Map<String, Object> attrs)
/*      */     throws ServiceException
/*      */   {
/* 2660 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.MODIFY_SMIME_CONFIG_REQUEST);
/*      */     
/* 2662 */     Element eConfig = req.addElement("config");
/* 2663 */     eConfig.addAttribute("name", configName);
/* 2664 */     eConfig.addAttribute("op", "modify");
/*      */     
/* 2666 */     addAttrElements(eConfig, attrs);
/*      */     
/* 2668 */     invoke(req);
/*      */   }
/*      */   
/*      */   public void removeConfigSMIMEConfig(String configName) throws ServiceException
/*      */   {
/* 2673 */     Element.XMLElement req = new Element.XMLElement(AdminConstants.MODIFY_SMIME_CONFIG_REQUEST);
/*      */     
/* 2675 */     Element eConfig = req.addElement("config");
/* 2676 */     eConfig.addAttribute("name", configName);
/* 2677 */     eConfig.addAttribute("op", "remove");
/*      */     
/* 2679 */     invoke(req);
/*      */   }
/*      */   
/*      */   public com.zimbra.cs.account.ShareLocator get(com.zimbra.common.account.Key.ShareLocatorBy keyType, String key) throws ServiceException
/*      */   {
/* 2684 */     throw new UnsupportedOperationException();
/*      */   }
/*      */   
/*      */   public com.zimbra.cs.account.ShareLocator createShareLocator(String id, Map<String, Object> attrs) throws ServiceException
/*      */   {
/* 2689 */     throw new UnsupportedOperationException();
/*      */   }
/*      */   
/*      */   public void deleteShareLocator(String id) throws ServiceException
/*      */   {
/* 2694 */     throw new UnsupportedOperationException();
/*      */   }
/*      */   
/*      */   public UCService createUCService(String name, Map<String, Object> attrs)
/*      */     throws ServiceException
/*      */   {
/* 2700 */     CreateUCServiceResponse resp = (CreateUCServiceResponse)invokeJaxb(new com.zimbra.soap.admin.message.CreateUCServiceRequest(name, attrs));
/* 2701 */     return new SoapUCService(resp.getUCService(), this);
/*      */   }
/*      */   
/*      */   public void deleteUCService(String zimbraId) throws ServiceException
/*      */   {
/* 2706 */     invokeJaxb(new com.zimbra.soap.admin.message.DeleteUCServiceRequest(zimbraId));
/*      */   }
/*      */   
/*      */   public UCService get(Key.UCServiceBy keyType, String key) throws ServiceException
/*      */   {
/* 2711 */     UCServiceSelector sel = new UCServiceSelector(toJaxb(keyType), key);
/*      */     try
/*      */     {
/* 2714 */       GetUCServiceResponse resp = (GetUCServiceResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetUCServiceRequest(sel));
/*      */       
/* 2716 */       return new SoapUCService(resp.getUCService(), this);
/*      */     } catch (ServiceException e) {
/* 2718 */       if (e.getCode().equals("account.NO_SUCH_UC_SERVICE")) {
/* 2719 */         return null;
/*      */       }
/* 2721 */       throw e;
/*      */     }
/*      */   }
/*      */   
/*      */   public List<UCService> getAllUCServices() throws ServiceException
/*      */   {
/* 2727 */     ArrayList<UCService> result = new ArrayList();
/* 2728 */     GetAllUCServicesResponse resp = (GetAllUCServicesResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetAllUCServicesRequest());
/* 2729 */     for (com.zimbra.soap.admin.type.UCServiceInfo ucServiceInfo : resp.getUCServiceList()) {
/* 2730 */       result.add(new SoapUCService(ucServiceInfo, this));
/*      */     }
/* 2732 */     return result;
/*      */   }
/*      */   
/*      */ 
/*      */   public String updatePresenceSessionId(String zimbraId, String username, String password)
/*      */     throws ServiceException
/*      */   {
/* 2739 */     UCServiceSelector sel = new UCServiceSelector(toJaxb(Key.UCServiceBy.id), zimbraId);
/*      */     
/*      */ 
/* 2742 */     com.zimbra.soap.admin.message.UpdatePresenceSessionIdRequest req = new com.zimbra.soap.admin.message.UpdatePresenceSessionIdRequest(sel, username, password);
/*      */     
/* 2744 */     UpdatePresenceSessionIdResponse resp = (UpdatePresenceSessionIdResponse)invokeJaxb(req);
/* 2745 */     return resp.getSessionId();
/*      */   }
/*      */   
/*      */   public void renameUCService(String zimbraId, String newName) throws ServiceException
/*      */   {
/* 2750 */     invokeJaxb(new com.zimbra.soap.admin.message.RenameUCServiceRequest(zimbraId, newName));
/*      */   }
/*      */   
/*      */   public void autoProvControl(String action) throws ServiceException
/*      */   {
/* 2755 */     invokeJaxb(new com.zimbra.soap.admin.message.AutoProvTaskControlRequest(com.zimbra.soap.admin.message.AutoProvTaskControlRequest.Action.fromString(action)));
/*      */   }
/*      */   
/*      */ 
/*      */   private static com.zimbra.soap.admin.type.CalendarResourceSelector.CalendarResourceBy toJaxb(Key.CalendarResourceBy provCalendarResourceBy)
/*      */     throws ServiceException
/*      */   {
/* 2762 */     return com.zimbra.soap.admin.type.CalendarResourceSelector.CalendarResourceBy.fromString(provCalendarResourceBy.toString());
/*      */   }
/*      */   
/*      */   private static CosSelector.CosBy toJaxb(Key.CosBy provCosBy)
/*      */     throws ServiceException
/*      */   {
/* 2768 */     return CosSelector.CosBy.fromString(provCosBy.toString());
/*      */   }
/*      */   
/*      */ 
/*      */   private static com.zimbra.soap.admin.type.CacheEntrySelector.CacheEntryBy toJaxb(Key.CacheEntryBy provCacheEntryBy)
/*      */     throws ServiceException
/*      */   {
/* 2775 */     return com.zimbra.soap.admin.type.CacheEntrySelector.CacheEntryBy.fromString(provCacheEntryBy.toString());
/*      */   }
/*      */   
/*      */ 
/*      */   private static com.zimbra.soap.admin.type.ServerSelector.ServerBy toJaxb(Key.ServerBy provServerBy)
/*      */     throws ServiceException
/*      */   {
/* 2782 */     return com.zimbra.soap.admin.type.ServerSelector.ServerBy.fromString(provServerBy.toString());
/*      */   }
/*      */   
/*      */   private static com.zimbra.soap.admin.type.AlwaysOnClusterSelector.AlwaysOnClusterBy toJaxb(Key.AlwaysOnClusterBy provAlwaysOnClusterBy)
/*      */     throws ServiceException
/*      */   {
/* 2788 */     return com.zimbra.soap.admin.type.AlwaysOnClusterSelector.AlwaysOnClusterBy.fromString(provAlwaysOnClusterBy.toString());
/*      */   }
/*      */   
/*      */   private static com.zimbra.soap.admin.type.UCServiceSelector.UCServiceBy toJaxb(Key.UCServiceBy provUCServiceBy)
/*      */     throws ServiceException
/*      */   {
/* 2794 */     return com.zimbra.soap.admin.type.UCServiceSelector.UCServiceBy.fromString(provUCServiceBy.toString());
/*      */   }
/*      */   
/*      */   private static AccountBy toJaxb(Key.AccountBy provAccountBy)
/*      */     throws ServiceException
/*      */   {
/* 2800 */     return AccountBy.fromString(provAccountBy.toString());
/*      */   }
/*      */   
/*      */   private static com.zimbra.soap.admin.type.DomainSelector.DomainBy toJaxb(Key.DomainBy provDomainBy) throws ServiceException
/*      */   {
/* 2805 */     return com.zimbra.soap.admin.type.DomainSelector.DomainBy.fromString(provDomainBy.toString());
/*      */   }
/*      */   
/*      */   private static com.zimbra.soap.admin.type.DistributionListSelector.DistributionListBy toJaxb(Key.DistributionListBy d)
/*      */     throws ServiceException
/*      */   {
/* 2811 */     return com.zimbra.soap.admin.type.DistributionListSelector.DistributionListBy.fromString(d.toString());
/*      */   }
/*      */   
/*      */ 
/*      */   public List<Server> getAllServers(String service, String clusterId)
/*      */     throws ServiceException
/*      */   {
/* 2818 */     List<Server> result = new ArrayList();
/* 2819 */     GetAllServersResponse resp = (GetAllServersResponse)invokeJaxb(new com.zimbra.soap.admin.message.GetAllServersRequest(service, Boolean.valueOf(true), clusterId));
/*      */     
/* 2821 */     for (ServerInfo serverInfo : resp.getServerList()) {
/* 2822 */       result.add(new SoapServer(serverInfo, this));
/*      */     }
/* 2824 */     return result;
/*      */   }
/*      */   
/*      */   public class MemcachedClientConfig
/*      */   {
/*      */     public String serverList;
/*      */     public String hashAlgorithm;
/*      */     public boolean binaryProtocol;
/*      */     public int defaultExpirySeconds;
/*      */     public long defaultTimeoutMillis;
/*      */     
/*      */     public MemcachedClientConfig() {}
/*      */   }
/*      */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/soap/SoapProvisioning.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */